}
boolean disconnect = shouldDisconnectAfterHandled(split[2].equals("HTTP/1.0"), headers) || !container.enablePersistentConnections();
boolean allowPost = container.allowPosts();
BucketFactory bf = container.getBucketFactory();
ToadletContextImpl ctx = new ToadletContextImpl(sock, headers, bf, pageMaker, container, userAlertManager, bookmarkManager, uri, container.generateUniqueID());
ctx.shouldDisconnect = disconnect;
/*
* copy the data into a bucket now,
* before we go into the redirect loop
*/
Bucket data;
boolean methodIsConfigurable = true;
String slen = headers.get("content-length");
if (METHODS_MUST_HAVE_DATA.contains(method)) {
// <method> must have data
methodIsConfigurable = false;
if (slen == null) {
ctx.shouldDisconnect = true;
ctx.sendReplyHeaders(400, "Bad Request", null, null, -1);
return;
}
} else if (METHODS_CANNOT_HAVE_DATA.contains(method)) {
// <method> can not have data
methodIsConfigurable = false;
if (slen != null) {
ctx.shouldDisconnect = true;
ctx.sendReplyHeaders(400, "Bad Request", null, null, -1);
return;
}
}
if (slen != null) {
long len;
try {
len = Integer.parseInt(slen);
if(len < 0) throw new NumberFormatException("content-length less than 0");
} catch (NumberFormatException e) {
ctx.shouldDisconnect = true;
ctx.sendReplyHeaders(400, "Bad Request", null, null, -1);
return;
}
if(allowPost && ((!container.publicGatewayMode()) || ctx.isAllowedFullAccess())) {
data = bf.makeBucket(len);
BucketTools.copyFrom(data, is, len);
} else {
FileUtil.skipFully(is, len);
if (method.equals("POST")) {
ctx.sendMethodNotAllowed("POST", true);