Table of Contents
What is HTTP?
Hypertext Transfer Protocol, as the name suggests it is a protocol(rules and regulations) for transfering information over a network. In simple words if someone wants to talk then they use a language(say english), here english is the protocol.
How is it different from other protocols?
Some characteristics which make it different from other protocols are:
-
Stateless: Each request is independent of other requests.
While it is stateless, It is important to note that state can be added using cookies, tokens, sessions, etc.
-
Client-Server model: It comprises of client and server, which means that there is someone(
client) who will ask(send request) for something(data) and someone else(server) will return(send response) that data.
-
Text-based: The request-response are text based and hence easy to understand and use.
Latest versions has become binary.
Is it exactly similar to that REST thing?
No, While everyone use REST and HTTP together they are in fact not the same.
| Point |
HTTP |
REST |
| Type |
Protocol |
Architectural style |
| Definition |
Defines data transfer rules |
Set of constraints for designing APIs |
| Purpose |
Transfers messages (web pages, data) |
Resource-oriented web services |
| Stateless |
Yes |
Yes (must be stateless) |
| Transport Options |
Only HTTP |
Usually HTTP, but not limited (can use others) |
| Methods |
GET, POST, PUT, DELETE, etc. |
Uses HTTP methods, mapped to resources |
| Resource Focus |
Not required |
Central – everything is a resource |
| Uniform Interface |
Methods provided (not enforced) |
Enforced; consistent resource access |
| Design Constraint |
None beyond basic protocol |
Must follow REST constraints |
| Caching |
Possible, using HTTP caching headers |
Explicit, REST responses indicate cacheability |
| Media Types |
Supports media types via headers |
Uses headers |
| Examples |
Web browser fetching a webpage |
REST API for managing users, orders, etc. |
How HTTP works?
when user types aneeshkhunteta.com , the browser asks the DNS server for IP. It will the try to establish TCP connection with the server by using the 3-way TCP handshaking.
3-way TCP handshaking is the process in which A send SYN request to B, then B sends SYN+ACK to A, then finally A send ACK to B. this way a TCP connection is established.
Evolution of HTTP
HTTP has evolved overtime, from only one method protocol to secured multiplexing protocol. It is important to know why soome version are better than others and what made these improvements necessary. while it is always preferred to use latest versions but one must see the tradeoffs and then decide.
HTTP/0.9
Was introduced in 1991.
-
Pros:
- Text Based
- Very simple, easy to debug
-
Cons:
- Only supports GET
- No headers support or metadata
- No media(MIME) types
- New-connection for every request
- Not secure
HTTP/1.0
Was introduced in 1996.
-
Pros:
- Header/Metadata support introduced
- Status codes were introduced
- Different content types were allowed
-
Cons:
- New-connection for every request
- Not secure
HTTP/1.1
Was introduced in 1997.
-
Pros:
-
Persistent Connections
Here connection was kept alive after the response is received by the browser, so that subsequent request do not waste time while performing 3-way handshake for every request.
-
Chunked transfer encoding(streaming Responses)
Streaming the Data(i.e. sending data in chunks) was introduced in this. when the browser don't have idea of the size of requested resource then the server will stream it. for eg. sports streams. This way data can be rendered as received rather than waiting for all of it.
-
Host Header
With host header one could tell which host on that particular IP they want to talk to. this helped in serving thousands of domains on one server.
-
Caching control
More controlled and customizable caching options were their in this version. introduced something called as Etag which meant that if the etag is not changed then the resource is not changed, and hence cached copy can be used.
-
Cons:
-
Head-of-line blocking
As it had persistent connections, that means that all requests were send one after another that means that request 2 needs to wait for request 1 to be completed. This brought overhead of blocking in HTTP layer. To counter this many browsers started creating multiple parallel TCP connections and requesting simultaneously on them. while this helped, it brought more overhead and load on the server to maintain so many connections.
HTTP/2.0
Was introduced in 2015.
-
Pros:
- Shifted from Text to binary
-
Multiplexing
many requests and responses could be send simultaneously over single TCP connection. which removed head-of-line blocking issues and prevented browser workaround which saved server's resources.
- Header compression(HPACK) was introduced which resulted in smaller and faster headers.
-
Server Push
server can proactively send resources.
-
Cons:
-
TCP HOL was still not resolved
You’re downloading CSS, JS, and an image over 1 HTTP/2 TCP connection.
If a packet from the image stream is lost → CSS + JS (which already arrived) are stuck waiting until retransmission succeeds.
- complex to debug.
HTTP/3.0
Was introduced in 2020.
-
Pros:
-
Built on QUIC(UDP-based Transpost) instead of TCP
- Uses Multiplexed streams, means no HOL blocking
- Has Built-in TLS which means it is always secure
- Has Faster(less RTTs) handshake, which results in lower latency.
- Has Connection IDs which survive IP changes.
- It is Ideal for mobiles, video heavy, low-latency requirements
- with the help of streams multiplexing, HOL was removed
- lowest-latency
-
Cons:
- requires QUIC support
- debugging is very hard
HTTPS
Secured HTTP is known as HTTPS. This is achieved by encrypting the request/response. It is done with the help of SSL/TLS certificates.
Before any exchange of data, server shares its certificate and public keys, browser verifies and create a secure session with the server and transfers encrypted data. It has become standard to use HTTPS, sites which don’t use it are flagged by the browsers and prompted to user as the site is not secure.
the title “thisisunsafe” can be used to bypass this and open an unsecured website.
Summary
Here, i have provided how HTTP grew and became what came to be known as the backbone of internet. This is very important to understand as these basics will lay foundation of scalable systems(tbh idk).
|