Merged branch 'master' into 'jetty-9.1'.

This commit is contained in:
Simone Bordet 2013-10-22 13:34:06 +02:00
commit dcbc0d9a21
1 changed files with 25 additions and 17 deletions

View File

@ -65,21 +65,25 @@ public abstract class BufferingResponseListener extends Listener.Adapter
HttpFields headers = response.getHeaders();
long length = headers.getLongField(HttpHeader.CONTENT_LENGTH.asString());
if (length > maxLength)
response.abort(new IllegalArgumentException("Buffering capacity exceeded"));
String contentType = headers.get(HttpHeader.CONTENT_TYPE);
if (contentType != null)
{
String charset = "charset=";
int index = contentType.toLowerCase(Locale.ENGLISH).indexOf(charset);
if (index > 0)
response.abort(new IllegalArgumentException("Buffering capacity exceeded"));
}
else
{
String contentType = headers.get(HttpHeader.CONTENT_TYPE);
if (contentType != null)
{
String encoding = contentType.substring(index + charset.length());
// Sometimes charsets arrive with an ending semicolon
index = encoding.indexOf(';');
String charset = "charset=";
int index = contentType.toLowerCase(Locale.ENGLISH).indexOf(charset);
if (index > 0)
encoding = encoding.substring(0, index);
this.encoding = encoding;
{
String encoding = contentType.substring(index + charset.length());
// Sometimes charsets arrive with an ending semicolon
index = encoding.indexOf(';');
if (index > 0)
encoding = encoding.substring(0, index);
this.encoding = encoding;
}
}
}
}
@ -89,12 +93,16 @@ public abstract class BufferingResponseListener extends Listener.Adapter
{
long newLength = buffer.length + content.remaining();
if (newLength > maxLength)
{
response.abort(new IllegalArgumentException("Buffering capacity exceeded"));
byte[] newBuffer = new byte[(int)newLength];
System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
content.get(newBuffer, buffer.length, content.remaining());
buffer = newBuffer;
}
else
{
byte[] newBuffer = new byte[(int)newLength];
System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
content.get(newBuffer, buffer.length, content.remaining());
buffer = newBuffer;
}
}
@Override