学习目的:希望能更好的了解Web容器的运行机制
学习方法:通过慢慢实现Tomcat的中的单个功能,最好可以组装一个完整的Tomcat容器。
学习时间:2017.7.13 8.14pm
学习进度:day1
1.HTTP协议
Request
POST /examples/default.jsp HTTP/1.1
Accept: text/plain; text/html
Accept-Language: en-gb
Connection: Keep-Alive
Host: localhost
User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 98) Content-Length: 33
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
lastName=Franks&firstName=Michael
包含
[method] [uri] [version]
header
entity
解析
一个reques包含三部分。
第一部分,请求的方法+空格+资源定位符+http版本号
第二部分,请求头名+:+英文空格+请求头值+“\r\n”
第三部分:请求实体
第二部分和第三部分必须有一行空格
Response
HTTP/1.1 200 OK
Server: Microsoft-IIS/4.0
Date: Mon, 5 Jan 2004 13:13:33 GMT
<html> <head> <title>HTTP Response Example</title> </head> <body> Welcome to Brainy Software </body> </html>
解析
第一部分:版本号+状态码+状态
第二部分:响应头名+:+英文空格+响应头值+“\r\n”
第三部分:响应实体
第二部分和第三部分必须有一行空格
2 一个简单的Servlet容器