修复HttpRequest.readHeader问题
This commit is contained in:
@@ -341,6 +341,7 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
} else if (context.lazyHeaders && getmethod) { //非GET必须要读header,会有Content-Length
|
} else if (context.lazyHeaders && getmethod) { //非GET必须要读header,会有Content-Length
|
||||||
int rs = loadHeaderBytes(buffer);
|
int rs = loadHeaderBytes(buffer);
|
||||||
if (rs != 0) {
|
if (rs != 0) {
|
||||||
|
buffer.clear();
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
this.headerParsed = false;
|
this.headerParsed = false;
|
||||||
@@ -349,6 +350,7 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
int rs = readHeaderLines(buffer, bytes);
|
int rs = readHeaderLines(buffer, bytes);
|
||||||
if (rs != 0) {
|
if (rs != 0) {
|
||||||
this.headerHalfLen = bytes.length();
|
this.headerHalfLen = bytes.length();
|
||||||
|
buffer.clear();
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
this.headerParsed = true;
|
this.headerParsed = true;
|
||||||
@@ -356,14 +358,14 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
this.headerHalfLen = this.headerLength;
|
this.headerHalfLen = this.headerLength;
|
||||||
}
|
}
|
||||||
bytes.clear();
|
bytes.clear();
|
||||||
this.readState = READ_STATE_BODY;
|
|
||||||
}
|
|
||||||
if (this.contentType != null && this.contentType.contains("boundary=")) {
|
if (this.contentType != null && this.contentType.contains("boundary=")) {
|
||||||
this.boundary = true;
|
this.boundary = true;
|
||||||
}
|
}
|
||||||
if (this.boundary) {
|
if (this.boundary) {
|
||||||
this.keepAlive = false; //文件上传必须设置keepAlive为false,因为文件过大时用户不一定会skip掉多余的数据
|
this.keepAlive = false; //文件上传必须设置keepAlive为false,因为文件过大时用户不一定会skip掉多余的数据
|
||||||
}
|
}
|
||||||
|
this.readState = READ_STATE_BODY;
|
||||||
|
}
|
||||||
if (this.readState == READ_STATE_BODY) {
|
if (this.readState == READ_STATE_BODY) {
|
||||||
if (this.contentLength > 0 && (this.contentType == null || !this.boundary)) {
|
if (this.contentLength > 0 && (this.contentType == null || !this.boundary)) {
|
||||||
if (this.contentLength > context.getMaxBody()) {
|
if (this.contentLength > context.getMaxBody()) {
|
||||||
@@ -376,6 +378,8 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
if (bytes.isEmpty()) {
|
if (bytes.isEmpty()) {
|
||||||
this.bodyParsed = true; //no body data
|
this.bodyParsed = true; //no body data
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
buffer.clear();
|
||||||
}
|
}
|
||||||
return lr > 0 ? lr : 0;
|
return lr > 0 ? lr : 0;
|
||||||
}
|
}
|
||||||
@@ -647,7 +651,7 @@ public class HttpRequest extends Request<HttpContext> {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bytes.putWithoutCheck(b);
|
bytes.put(b);
|
||||||
}
|
}
|
||||||
size = bytes.length();
|
size = bytes.length();
|
||||||
byte[] content = bytes.content();
|
byte[] content = bytes.content();
|
||||||
|
|||||||
@@ -946,6 +946,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void error(Throwable t) {
|
protected void error(Throwable t) {
|
||||||
|
refuseAlive();
|
||||||
finish500();
|
finish500();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user