Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of Pseudo/Colon Header Fields

Tags:

As the title suggests, I'm looking for some information on the purpose of pseudo/colon header fields, i.e. I want to know why we have a second type of header field...

Also - I know pseudo/colon header fields are used in http2 in place of the message and status lines (^^^the reason for which I don't know^^^); but are pseudo/colon header fields used in http1 to relay different information (from status and request)?

like image 541
Nathodius Avatar asked Jun 17 '15 18:06

Nathodius


People also ask

What are pseudo header fields?

The TCP pseudo header is added to the beginning of the TCP segment only during the checksum calculation and is not sent as part of the TCP segment. The use of the TCP pseudo header assures the receiver that a routing or fragmentation process did not improperly modify key fields in the IP header.

What is pseudo header in http2?

In HTTP/2, a series of "pseudo-headers" is used to send key information about the message. Most notably, several pseudo-headers effectively replace the HTTP/1 request line and status line. In total, there are five pseudo-headers: :method - The HTTP method of the request, such as GET or POST .

Why do we use Httpheaders?

HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon ( : ), then by its value. Whitespace before the value is ignored.

Should HTTP headers be capitalized?

Just as in HTTP/1. x, header field names are strings of ASCII characters that are compared in a case-insensitive fashion. However, header field names MUST be converted to lowercase prior to their encoding in HTTP/2.


1 Answers

The purpose of the pseudo header fields was to unify the way the request/response information was carried in SPDY and later in HTTP/2 (which is based on SPDY).

When SPDY was designed (but also HTTP/2) there was a need to transport request or response information that is formatted in different ways.

The HTTP headers are (key, value) pairs, that's easy.

However, there is the concept of the HTTP method. That happens to be the first token of a request line, so it's not a tuple; its key is defined by its position (the first token) and its value is the actual characters present on the request line that form the first token.

Same goes with the request target, and HTTP version: they are the second and the third token of the request line.

So conceptually, a HTTP request can be represented with pairs in this way, for example:

(method, GET)   (target, /)   (version, HTTP/1.1)   (Connection, close)   (Accept, *)   

However, "method", "target" and "version" could not be used as plain HTTP headers, because they were never reserved as standard HTTP header names by the HTTP specification, and people could have used them as custom HTTP header names (imagine a REST API using the "version" header).

HTTP/2 needed a way to carry those pairs in a homogeneous way, as pairs, because that would have simplified (a lot) the protocol.

Hence, the introduction of special names for the extra information carried by the request and response lines. That extra information is positional in HTTP/1.1, but a normal pair in HTTP/2, making HTTP/2 more homogeneous in this respect: it just carries pairs. So much so, that the HTTP/2 frame that carries request and response information is the same and it's just called HEADERS.

The pseudo header names where chosen to begin with a colon because that would be an illegal character for a header name in HTTP/1.1. HTTP/1.1 does not use pseudo header names.

like image 58
sbordet Avatar answered Oct 07 '22 22:10

sbordet