HTTP 协议报文格式
- 请求报文
- 响应报文
HTTP Satus Code
3xx Redirection
-
304
: NOT MODIFIED
A conditional GET or HEAD request has been received and would have resulted in a 200 OK response if it were not for the fact that the condition evaluated to false.
4xx: Client Error
401
: UNAUTHORIZED
The request has not been applied because it lacks valid authentication credentials for the target resource.404
: NOT FOUND
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.405
: METHOD NOT ALLOWED
The method received in the request-line is known by the origin server but not supported by the target resource. (对于请求所标识的资源,不允许使用请求行中所指定的方法。)407
: PROXY AUTHENTICATION REQUIRED
Similar to401 Unauthorized
, but it indicates that the client needs to authenticate itself in order to use a proxy.
HTTP Methods
POST
-
- application/x-www-form-urlencoded
- multipart/form-data
- application/json
- text/xml
HTTP headers
Etag
Etag(Entity tag) 具体解释: 什么是ETag
Tornado/1.1 web.py 源码:
if (self._status_code == 200 and self.request.method == "GET" and
"Etag" not in self._headers):
hasher = hashlib.sha1()
for part in self._write_buffer:
hasher.update(part)
etag = '"%s"' % hasher.hexdigest()
inm = self.request.headers.get("If-None-Match")
if inm and inm.find(etag) != -1:
self._write_buffer = []
self.set_status(304)
else:
self.set_header("Etag", etag)
location
跳转(重定向)
当浏览器接受到头信息中的 Location: xxxx 后,就会自动跳转到 xxxx 指向的URL地址.
例如,
header["location"] = "http://www.baidu.com/"
keep-alive
具体阅读: HTTP Keep-Alive是什么?如何工作?
read more