Skip to content

Instantly share code, notes, and snippets.

@GingerBear
Created November 1, 2016 14:09
Show Gist options
  • Save GingerBear/0f6264ab4cd5c614169c034d433428e8 to your computer and use it in GitHub Desktop.
Save GingerBear/0f6264ab4cd5c614169c034d433428e8 to your computer and use it in GitHub Desktop.
http.MD

HTTP/0.9

  • only GET
  • only HTML format
  • TCP close after request
GET /index.html
<html>
  <body>Hello World</body>
</html>








HTTP/1.0

  • add POST, HEAD
  • add HTTP header
    • status code
    • User-Agent
    • Content-Type
    • ...
  • header must be ASCII, body can be anything (with content type, or MIME type)
  • Content-Encoding for can be used for compression
GET / HTTP/1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5)
Accept-Encoding: gzip, deflate
Accept: */*
HTTP/1.0 200 OK 
Content-Type: text/plain
Content-Length: 137582
Content-Encoding: gzip
Expires: Thu, 05 Dec 1997 16:00:00 GMT
Last-Modified: Wed, 5 August 1996 15:55:28 GMT
Server: Apache 0.84

<html>
  <body>Hello World</body>
</html>
  • problem:
    • TCP closed by default after each request (nonstandard Connection: keep-alive to keep connection)








HTTP/1.1

  • Connection: keep-alive by default
  • Connection: close explicitly to close TCP connection
  • pipelining
    • in one connection, client can send multiple request without response
  • Content-Length seperate responses in pipelining
  • or use Transfer-Encoding: chunked for time-comsuming response (only can know content length after it's done)
HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked

25
This is the data in the first chunk

1C
and this is the second one

3
con

8
sequence

0
  • add PUT, PATCH, HEAD, OPTIONS, DELETE
  • problem:
    • in one connection, server response one after another (Head-of-line blocking)
    • uncompressed header (large cookies)







HTTP/2

  • called frame: HEADERS frame, DATA frame, all can be binary
  • multiplexing: both client and server can send request/response without blocking
  • stream: data with a stream id out of order. Ability to cancel without close connection
  • header can be gzipped
  • reduendent header are saved in a table, only need to send table index.
  • server push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment