Skip to content

Instantly share code, notes, and snippets.

@shivam1283
Created June 5, 2022 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shivam1283/06c1bfa60e353e6101cd458618d7f0a9 to your computer and use it in GitHub Desktop.
Save shivam1283/06c1bfa60e353e6101cd458618d7f0a9 to your computer and use it in GitHub Desktop.
Networking

Traditional HTTP requests flow throught the network "pipe" (TCP connection) and the pipe only allows requests to flow in 1 direction ("to" or "from") and only 1 request can be be sent through the at once (Single-plexing).
Image

HTTP 1.1 allows browser to form 6 such TCP connections to the server. This approach was quite expensive as servers held resource descritptors which eats a lot of server memory. Image

HTTP2 enabled multiplexing thought the same network pipe. The pipe has different streams and each stream carriers an ID which lets client map the responses to its respective client.

HTTP2

Features

Mutiplexing

Image

The server gets multiple requests with the stream ID from a client and its process those requests. The responses for those requests are then tagged with the respective stream ID and send back to the server.

HTTP/2 Push

Push

If the client makes the request for a page like index.html the client might also need other files like main.js, main.css and img.jpg so just push them along with the response. This features need to be configured on the configured and the client should also be able to handle such responses.

Compression (headers and data)

HTTP/2 enables the compression of data as well as the headers also because there is a streamID already present as an identifier.

Always secure

HTTP/2 can't be done on any port. It has to be on 443

Protocol negotiation during TLS (ALPN)

We may inject our functionality when establishing the connection

Cons of HTTP/2

Can be abused when configured incorrectly

The server might "push" unneccesary responses to the client overloading the stream while the client may have those resources cached on to its memory.

Can be slower in mixed moded

Mixed mode means that the server is supporting HTTP/2 while the intermediate load balancers, proxies or reverse proxies are supporting HTTP/1 only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment