跳到主要内容

HTTP

Versions

VersionDescription
HTTP0.9只有GET方法/没有headers
HTTP1.0一个TCP连接只能发送一个HTTP请求
HTTP1.1Connection: Keep-Alive/Connection: Pipeline
SPDY→HTTP2Binary Framing(二进制分帧)/Multiplexing(多路复用)/Header Compression(头部压缩)/Server Push(服务器推送)
QUIC→HTTP3UDP

Protocol

Format

# Request
Method PATH HTTP/Version
Headers

Body

# Response
HTTP/Version Status Code
Headers

Body

Request Methods

NameTypeDescription
Connecthop-by-hop
DELETEend-to-end
GETend-to-end
HEADend-to-end
OPTIONSend-to-end
PATCHend-to-end
POSTend-to-end
PUTend-to-end
TRACEend-to-end

Response Status Code

CodeNameStatusDescription
100Continue
101Switching Protocol
102ProcessingDeprecated
103Early HintsExperimental
200OK
201Created
202Accepted
203Non-Authoritative Information
204No Content
205Reset Content
206Partial Content
207Multi-StatusWebDAV
208Already ReportedWebDAV
226IM Used
300Multiple Choices
301Moved Permanently
302Found
303See Other
304Not Modified
307Temporary Redirect
308Permanent Redirect
400Bad Request
401Unauthorized
402Payment Required
403Forbidden
404Not Found
405Method Not Allowed
406Not Acceptable
407Proxy Authentication
408Request Timeout
409Conflict
410Gone
411Lenght Required
412Precondition Failed
413Content Too Large
414URI Too Long
415Unsupported Media Type
416Range Not Satisfiable
417Expectation Failed
418I’m a teapot
421Misdirected Request
422Unprocessable Content
423Locked
424Failed Dependency
425Too Early
426Upgrade Required
428Precondition Required
429Too Many Requests
431Request Header Field Too Large
451Unavailable For Legal Reasons
500Internal Server Error
501Not Implemented
502Bad Gateway
503Service Unavailable
504Gateway Timeout
505HTTP Version Not Supported
506Variant Also Negotiates
507Insufficient Storage
508Loop Detected
510Not Extended
511Network Authentication Required

Headers

NameTypeEnd/HopStatusDescription
AcceptRequest
Accept-CHRequest只在HTTPS可用
Accept-CH-LifetimeRequestDeprecated
Accept-CharsetDo not use this header. Browsers omit this header and servers should ignore it
Accept-Encoding
Accept-Language
Accept-Patch
Accept-Post
Accept-Ranges
Access-Control-Allow-Credentials
Access-Control-Allow-Headers
Access-Control-Allow-Methods
Access-Control-Allow-Origin
Access-Control-Expose-Headers
Access-Control-Max-Age
Access-Control-Request-Headers
Access-Control-Request-Method
Age
Allow
Alt-Svc
Authorization
Cache-Control
Clear-Site-Data
Connection

Security

SOP

  • Include
    • XMLHttpRequest(JavaScript)
    • iframe DOM
    • Cookie/LocalStorage/IndexDB
  • Exclude
    • script(jsonp)
    • img
    • style

CORS

  • CORS

  • postMessage(DOM Cross Origin:iframe)

    # Send
    var target = window.open('https://example.com');
    target.postMessaget('Post Message');
    # Receive
    window.addEventListener("message", receiveMessage, false);
  • JSONP

  • document.domain

  • window.name

  • location.hash

CSP

Client

Server

Interface

LanguageInterface
PythonWSGI/ASGI
RubyRack
Phpmod_php/PHP-FPM
CGI
FastCGI

Reference