修改HttpResponse.finish(byte[])
This commit is contained in:
@@ -614,15 +614,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void finish(final byte[] bs) {
|
public void finish(final byte[] bs) {
|
||||||
if (isClosed()) return; //避免重复关闭
|
this.finish(this.contentType, bs);
|
||||||
if (this.context.getBufferCapacity() >= bs.length) {
|
|
||||||
ByteBuffer buffer = getBodyBufferSupplier().get();
|
|
||||||
buffer.put(bs);
|
|
||||||
buffer.flip();
|
|
||||||
this.finish(false, buffer);
|
|
||||||
} else {
|
|
||||||
this.finish(false, ByteBuffer.wrap(bs));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -633,15 +625,30 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
*/
|
*/
|
||||||
public void finish(final String contentType, final byte[] bs) {
|
public void finish(final String contentType, final byte[] bs) {
|
||||||
if (isClosed()) return; //避免重复关闭
|
if (isClosed()) return; //避免重复关闭
|
||||||
this.contentType = contentType;
|
final byte[] content = bs == null ? new byte[0] : bs;
|
||||||
if (this.context.getBufferCapacity() >= bs.length) {
|
if (!this.headsended) {
|
||||||
ByteBuffer buffer = getBodyBufferSupplier().get();
|
this.contentType = contentType;
|
||||||
buffer.put(bs);
|
this.contentLength = content.length;
|
||||||
buffer.flip();
|
ByteBuffer headbuf = createHeader();
|
||||||
this.finish(false, buffer);
|
if (headbuf.remaining() >= content.length) {
|
||||||
|
headbuf.put(content);
|
||||||
|
headbuf.flip();
|
||||||
|
super.finish(false, headbuf);
|
||||||
|
} else {
|
||||||
|
headbuf.flip();
|
||||||
|
super.finish(false, new ByteBuffer[]{headbuf, ByteBuffer.wrap(content)});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.finish(false, ByteBuffer.wrap(bs));
|
if (this.context.getBufferCapacity() >= content.length) {
|
||||||
|
ByteBuffer buffer = getBodyBufferSupplier().get();
|
||||||
|
buffer.put(content);
|
||||||
|
buffer.flip();
|
||||||
|
this.finish(false, buffer);
|
||||||
|
} else {
|
||||||
|
this.finish(false, ByteBuffer.wrap(content));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user