之前提到tomcat的http消息由SocketProcessor处理,通过init时注册的handler传给Http11ConnectionHandler::process. 之后调用Http11Processor::process,在这个函数中完成请求的整个过程。
使用chrome中请求:http://127.0.0.1:8090/index.html
1. 在inputBuffer.parseRequestLine(false);中解析http头中的第一行
request.method().setBytes(buf,start, pos - start); //GET
request.unparsedURI().setBytes(buf,start, end - start); // /index.html
request.requestURI().setBytes(buf,start, end - start); // /index.html
request.protocol().setBytes(buf,start, end - start);// HTTP/1.1
2. 在inputBuffer.parseHeaders();中解析http头将内容保存在headers。
===MimeHeaders ===
host= 127.0.0.1:8090
connection= keep-alive
accept= text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
user-agent= Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/30.0.1599.101 Safari/537.36
accept-encoding= gzip,deflate,sdch
accept-language= zh-CN,zh;q=0.8
3. prepareRequest();根据http头设置filter。
4. adapter.service(request,response);交给container处理请求,返回response。
5. endRequest();将response返回给客户端。