if (!getInputBuffer().parseRequestLine(keptAlive)) {
if (handleIncompleteRequestLineRead()) {
break;
}
}
在这个过程,先最多读取8192个字节,可在server.xml或context.xml中配置protocol 的maxTrailerSize属性,未设置则默认为8192。
然后根据读取到头信息,进行解析,
a、请求方法,get或是post等,
b、请求URL,包括URL中的请求参数
c、请求协议类型,一般为http/1.1
3、解析完整的头信息
// Currently only NIO will ever return false here
if (!getInputBuffer().parseHeaders()) {
// We've read part of the request, don't recycle it
// instead associate it with the socket
openSocket = true;
readComplete = false;
break;
}
4、CoyoteAdapter对象处理请求
rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE);
adapter.service(request, response);
// Handle when the response was committed before a serious
// error occurred. Throwing a ServletException should both
// set the status to 500 and set the errorException.
// If we fail here, then the response is likely already
// committed, so we can't try and set headers.
if(keepAlive && !error) { // Avoid checking twice.
error = response.getErrorException() != null ||
(!isAsync() &&
statusDropsConnection(response.getStatus()));
}
setCometTimeouts(socketWrapper);
adapter.service(request, response); 这一步的处理,较为复杂,进入了tomcat的pipeline的处理流程中,最终将调用web应用的filter、servlet。
5、处理完请求,并做一些善后事宜,如重置processor中request, response对象,以便下一次使用。