Web and HTTP First, a review… ▪ web page consists of objects ▪ object can be HTML file, JPEG image, Java applet, audio file,… ▪ web page consists of base HTML-file which includes several referenced objects ▪ each object is addressable by a URL, e.g.,网页有对象组成 网页有基本HTML组成 包括多个引用对象 每个对象都可以通过URL寻址HTTP 的工作流程 HTTP: hypertext transfer protocol ▪ Web’s application layer protocol ▪ client/server model • client: browser that requests, receives, (using HTTP protocol) and “displays” Web objects • server: Web server sends (using HTTP protocol) objects in response to requests客户端:请求、接收(使用 HTTP 协议)和 "显示 "网络对象的浏览器 - 服务器: 服务器:网络服务器(使用 HTTP 协议)发送对象以响应请求
HTTP overview (continued) uses TCP: ▪ client initiates TCP connection (creates socket) to server, port 80 ▪ server accepts TCP connection from client ▪ HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server) ▪ TCP connection closed 1客户机启动与服务器TCP连接创建socket 端口 2服务器接受来自客户机的TCP的连接 3客户端与服务器之间交换HTTP信息 4关闭TCP连接
HTTP is “stateless”无状态 ▪ server maintains no information about past client requests服务器不维护过去客户端请求信息protocols that maintain “ state ” are complex! ▪ past history (state) must be maintained ▪ if server/client crashes, their views of “ state ” may be inconsistent, must be reconciled
HTTP connections non-persistent HTTP ▪ at most one object sent over TCP connection • connection then closed最多一个对象在TCP连接 连接后会关闭 ▪ downloading multiple objects required multiple connections persistent下载多个对象需要多个连接 HTTP ▪ multiple objects can be sent over single TCP connection between client, server客户端和服务器之间的单个TCP连接可以发送多个对象
Non-persistent HTTP: response time RTT (definition): time for a small packet to travel from client to server and back一个数据包从客户端传输到服务器在返回的时间HTTP response time: ▪ one RTT to initiate TCP connection ▪ one RTT for HTTP request and first few bytes of HTTP response to return ▪ file transmission time ▪ non-persistent HTTP response time = 2RTT+ file transmission time启动 TCP 连接的一个 RTT ▪ HTTP 请求和 HTTP 响应返回的前几个字节的一个 RTT ▪ 文件传输时间 ▪ non-persistent HTTP 响应时间 = 2RTT+ 文件传输时间
Persistent HTTP non-persistent HTTP issues: ▪ requires 2 RTTs per object ▪ OS overhead for each TCP connection ▪ browsers often open parallel TCP connections to fetch referenced objects每个 TCP 连接需要 2 个 RTT ▪ 每个 TCP 连接的操作系统开销 ▪ 浏览器经常打开并行 TCP 连接以获取引用对象 persistent HTTP: ▪ server leaves connection open after sending response ▪ subsequent HTTP messages between same client/server sent over open connection ▪ client sends requests as soon as it encounters a referenced object ▪ as little as one RTT for all the referenced objects 同一客户端/服务器之间的后续 HTTP 消息通过打开的连接发送 ▪ 客户端在遇到引用对象时立即发送请求 ▪ 所有引用对象只需一个 RTT
HTTP request message ▪ two types of HTTP messages: request, response ▪ HTTP request message: • ASCII (human-readable format)
3、HTTP request message: general format HTTP 有两类报文: • 请求报文——从客户向服务器发送请求报文。 • 响应报文——从服务器到客户的回答。 由于 HTTP 是面向正文的(text-oriented),因 此在报文中的每一个字段都是一些 ASCII 码串, 因而每个字段的长度都是不确定的
Method types HTTP/1.0: ▪ GET ▪ POST ▪ HEAD • asks server to leave requested object out of response 要求服务器在响应中忽略请求对象HTTP/1.1: ▪ GET, POST, HEAD ▪ PUT • uploads file in entity body to path specified in URL field将实体主体上文件上传到URL字段中指定路径 ▪ DELETE • deletes file specified in the URL field删除URL字段中指定文件
Uploading form input POST method: • web page often includes form input • input is uploaded to server in entity body网页通常包含表单输入 输入在实体正文中上传到服务器 URL method: • uses GET method • input is uploaded in URL field of request line 使用GET方法 在请求行的URL字段中上传输入内容
HTTP response status codes status code appears in 1st line in server-to-client response message.状态代码出现在服务器到客户端响应信息的第一行