HTTP — Hyper Text Transfer Protocol
What is HTTP
HTTP — is an application layer protocol that allows web-based applications to communicate and exchange data
It is based on TCP/IP
Usage: Originally designed to fetch HTML documents and send it to client.
Difference between HTTP 1.1 vs HTTP2
Shortcomings in HTTP 1.1
Head of line Blocking — HTTP 1. 1 has fixed number of TCP connections — 6 TCP connections per hostname. This means, at the max, only 6 parallel requests can be made to the server. A new request has to wait for the previous request on the same connection to complete before the client can make a new request.
Example: (for 1 TCP connection): Consider, client has parsed the index.html file and has found that it needs, STYLE.CSS & SCRIPT.JS files to load the web page. In this case, client can’t make parallel requests requesting CSS & JS at the same time. First it has to make a request for STYLE.CSS sheet and has to wait for the request to complete before the client can make a new request for SCRIPT.JS.
Header Repetition — Since HTTP 1.1 is stateless, each request which is sent has the header data. This leads to the repetition of headers. Also, the headers cannot be compressed in HTTP 1.1
Solutions in HTTP 2.0 for the above shortcomings
Single TCP connection is used
Multiple streams are created in the above single TCP connection in which every HTTP request is sent as stream. So, client can make a parallel request to the server and doesn’t have to wait for the previous request on the same connection to complete
TLS is mandatory for HTTP 2.0
HPACK — Header data is separated from the actual payload and allows compression
PUSH — Push allows to send mandatory resources in advance
Example -> whenever a client requests for index.html, server can use PUSH and send the script.js, style.css files along with the response for the initial request.
HTTP Version History
HTTP 0.9–(year: 1991) — Originally designed for transferring HTML documents. Had only GET, POST, HEAD methods
HTTP 1.0 — (year: 1996) — PUT, DELETE, LINK and UNLINK methods were introduced
HTTP 1.1 — (year: 1997) — CORS, Keep Alive were introduced.