12

花了半天时间,看了一次http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

下面是相关的笔记和理解,
感觉很多Status Code在实际的BS通信中都不常见,
更多像是为了定义完备的协议语义,
而这些语义现在已经部分由更上层的协议或者应用实现。

1xx Informational

100 Continue
    如果server可能拒绝request,则client只发送header部分,试探server的反应
    如果server接受,则返回100,于是client再发送剩余的body部分
101 Switch Protocol

2xx Successful

200 OK
201 Created

    有资源因Request而产生
202 Accepted
    Request要求的动作已经被记录,但真正的动作要等待若干时间才执行,而且不保证一定执行
203 Non-Authoritative Information
204 No Content

    google.cn的web server会返回
205 Reset Content
206 Partial Content

    用于断点续传,起始位置由Range指定。(可以参考迅雷的输出)

3xx Redirection

    User Agent需要处理循环的问题
300 Multiple Choices
    目标已变,有若干个替代品可供选择
301 Moved Permanently
    目标URI在Location里定义,除了HEAD和GET请求外,不能自动重定向
    对SEO不会有负面作用
302 Found
    临时重定向,是否用Moved Temporarily这个名字比较合适?
    目标URI在Location里定义,除了HEAD和GET请求外,不能自动重定向
    对SEO有负面作用
303 See Other
    和302类似,但期待User Agent用GET来请求Location里指定的URI
304 Not Modified
    通常Request会带If-Modified-Since
    不能带message-body
305 Use Proxy
    期待User Agent会使用Location中指定的Proxy地址,来访问数据
    只能由origin server产生
306 (not used)
    之前的版本用过,已经废弃,作为保留字
307 Temporary Redirect
    没看出和302有什么不同
    只有HTTP/1.1支持

4xx Client Error

    在message-body中,可以自定义给User的提示
400 Bad Request
    server不能理解Request的格式
    用telnet可以很容易模拟
401 Unauthorized
    不能通过HTTP Authentication
    response header必须包含WWW-Authoricate,request header可能包含Authorization
402 Payment Required
    保留字
403 Forbidden
    如果不希望暴露过多的信息,可以用404代替
404 Not Found
    最常见的4字头Status Code,通常会自定义
405 Method Not Allowed
    response header需要包含Allow,列出支持的method
406 Not Acceptable
    response不被request header中的Accept做支持
    除了HEAD,response会给出包含更多信息的entity
    entity format由request header中的Content-Type决定
407 Proxy Authentication Required
    与401类似
    Proxy的response header必须包含Proxy-Authenticate
408 Request Timeout
409 Conflict

    需要User干预解决
    在PUT的时候可能遇到
410 Gone
    URI已经不存在,且不提供3xx来重定向
    如果server没有足够的信息来判断URI的不存在是temporary还是permanent,可以用404代替
411 Length Required
    request header中缺少Content-Length
412 Precondition Failed
413 Request Entity Too Large

    如果只是temporary,可以包含Retry-After,指定重试的时间间隔
414 Request-URI Too Long
    有几种可能导致这个返回码的情况
    将POST当成了GET
    循环重定向,每次都append上当前URI
    攻击
415 Unsupported Media Type
    416 Requested Range Not Satisfiable

    参考206
417 Expectation Failed
    不能满足request header中的Expect,参考100

5xx Server Error

500 Internal Server Error
    在server没有输出正确的response header的时候会出现
501 Not Implemented
502 Bad Gateway

    由gateway或者proxy返回,表明上游server不能返回请求的URI
503 Service Unavailable
    server可能过载,或者正在维护
    可以返回Retry-After,如果没有,则视作500
504 Gateway Timeout
    上游server不能及时返回
505 HTTP Version Not Supported

Tagged with:
十一 24

想想做web已经一年半了,还没有系统的看过web的基础协议。
所以找了rfc2616的pdf版本,准备详细了解一下。

中文版也是有的,也曾下载看过,不过翻译质量实在不敢恭维。
还是和英文书一样,看原版吧。

非常有论文风格的一个标准。
一开始先是下定义,不过有几个定义我反复看了几次,还是不清楚具体的区别。

proxy
An intermediary program which acts as both a server and a client for the purpose of making requests on behalf
of other clients. Requests are serviced internally or by passing them on, with possible translation, to other
servers. A proxy MUST implement both the client and server requirements of this specification. A “transparent proxy” is a proxy that does not modify the request or response beyond what is required for proxy authentication and identification. A “non-transparent proxy” is a proxy that modifies the request or response in order to provide some added service to the user agent, such as group annotation services, media type transformation, protocolreduction, or anonymity filtering. Except where either transparent or non-transparent behavior is explicitly stated, the HTTP proxy requirements apply to both types of proxies.
gateway
A server which acts as an intermediary for some other server. Unlike a proxy, a gateway receives requests as if it were the origin server for the requested resource; the requesting client may not be aware that it is
communicating with a gateway.
tunnel
An intermediary program which is acting as a blind relay between two connections. Once active, a tunnel is not considered a party to the HTTP communication, though the tunnel may have been initiated by an HTTP request. The tunnel ceases to exist when both ends of the relayed connections are closed.

有些实际例子就好了。

Tagged with:
preload preload preload