HTTP
Last updated
Last updated
Follows a classical client-server model
, with a client opening a connection to make a request, and then waiting until it receives a response from the server.
It's a stateless protocol (doesn't retain session state from previous requests), although with the addition of cookies state was added to some client-server interactions. (making HTTP stateless but not sessionless)
Designed in the early 1990s it has evolved over time.
It's an application layer protocol sent over TCP, or over a TLS-encrypted TCP connection.
Was extremely simple, requests consisted of a single line and started with only possible method GET
followed by the path to the resource.
There were no headers in the request, so only HTML files could be transmitted.
There were no status codes.
First published in 1996.
With:
Versioning information HTTP/1.0
now appended to the GET
line.
Status code was also sent at the beginning of the response.
The concept of headers
was introduced for request
and responses
.
Other types of documents could be transmitted thanks to the Content-Type
header.
First published in 1997.
The standard version. It clarified ambiguities and more improvemets:
Reusable connections.
Pipelining was added, allowing a second request to be sent before the answer to the first was fully transmitted. (lowering latency of communication)
Chunked reponses now supported.
Additional cache controls added.
Content negotiation, including language, encoding and type were introduced.
Thanks to Host
header, the ability to host different domains from the same IP address allowed server collocation.
With the increase of complexity from web pages, Google implemented in the early 2010 SPDY, serving as the foundation for the version 2 of the protocol.
Officially standardized in 2015.
Made some changes related to the last version:
It's now a binary protocol rather than a text protocol.
It's a multiplexed protocol, so parallel requests can be made over the same connection.
But still runs over a single TCP
connection, so packtet loss detection and retransmission can block all streams.
It compresses headers, removing duplication and overhead of data transmissions, since headers are often similar among sets of requests.
Smarter CDN caching mechanism with Alt-Svc
.
Introduction of client hints
allowing the client to proactively communicate information about its requirements and hardware constraints.
To update from HTTTP/1.1, only an up-to-date server that communicate with a recent browser was necessary, without significant work for web developers.
The next major version now uses QUIC
instead of TCP
for transport layer portion.
Designed to provide much lower latency, QUIC
runs multiple streams over UDP
and implements packet loss detection and retransmission independently for each stream.
The original model of HTTP, and the default one in HTTP/1.0
.
Each HTTP request is completed on its own connection, this means a TCP handshake happens before each request and these are serialized.
TCP handshake itself is time-consuming, but TCP connections adapts to it load, becoming more efficient with more sustained connections.
Short-lived on the other hand don't make use of this efficiency feature of TCP.
In HTTP/1.1
this model is used if Connection
header value is set to close
.
A persistent connection is onw which remains open for a period of time, and can be reused for several requests. (also known as keep-alive connection)
It saves the need for a new TCP handshake.
Persistent connections have drawbacks, consuming server resources even when idling.
In HTTP/1.1
persistent connection are default, even if not using Connection
header.
By default HTTP requests are issued sequentially, where the next request is only issued once the response to the current has been received.
Pipelining is the process to send successive requests over the same persisten connection without waiting for the answer, avoiding latency of the connection.
Not all types of HTTP can be pipelined; only idempotent methods (GET
, HEAD
, PUT
and DELETE
), since should a failure happen, the pipeline content can be repeated.
Deprecated technique.
Where client open several connection to each domain, sending parallel requests.
There is a risk of triggering DoS
protection on the server side if attempting to open more than 6 parallel connections.
HTTP messages are how data is exchanged between server-client.
Messages sent by the Client to the Server, to initiate an action on the server.
Request line: The first line of the request that consist of:
Method: like Get
, Put
, ..., or HEAD
or OPTIONS
. These describes the action to be performed.
Target: usually a URL, or absolute path of the protocol, port and domain.
Version: Protocol version which defines the structure of the remaining message.
Headers: contains different header key and values and can be divided in several groups.
Body: the request body is optional, and some Methods shoudn't have one.
Messages sent by the Server to the Client.
Status line: The first line of the response that consist of:
Version: Protocol version.
Status Code: Indicating success or failure of the request.
Status Text: Brief, purely informational, textual description of the status code.
Headers: contains different header key and values and can be divided in several groups.
Body: the response body is also optional, when only a status code is sufficient.
It divides HTTP/1.x
messages into frames which are embedded in a stream.
Data and header frames are separated, which allows header compression.
The streams can be combined together with multiplexing, allowing more efficient use of underlying TCP connections.
HTTP frames are now transparent to Web developers and NO changes are needed in the APIs to use HTTP frames.
An important way to increase the performance of a website and lower bandwidth needs. For some document, size reduction of up to 70%.
In practice, web developers don't need to implement compression mechanisms, browsers and servers implemented already. It just needs to be configured.
HTTP cache stores a response associated with a request and reuses the stored response for subsequent requests.
A private cache is tied to a specific client, typically a browser cache.
If a response contains personalized content and you want to store the response only in the private cache, specify a private
directive.
Are located between the client and the server and can store responses that can be shared among users.
Proxy Caches
Some proxies implement caching to reduce traffic out of the network.
Usually managed by the service developer, so must be controlled by appropriate headers.
Cache-Control: no-store, no-cache, ...
Managed Caches
Are explicitly deployed by service developers to offload the origin server.
Like reverse proxies
, CDN
and service workers
in combination with Cache API
.
Cache-Control: no-store