2

For HTTP/0.9:

GET /

For HTTP/1.0:

GET / HTTP/1.0

For HTTP/1.1:

GET / HTTP/1.1
Host: example.com

What is the request line for HTTP/2? Is it something like:

GET / HTTP/2.0

Or HTTP/2?

1 Answers1

6

Neither; there is not such request line, because HTTP/2 (RFC 7540) does not use lines but frames (section 4) for communication. Inside those frames, headers are exchanged using HTTP header fields (section 8.1.2).

The client must first know whether the server supports HTTP/2.

  • For HTTP (section 3.2), this is done with Upgrade: h2c headers:

    > GET / HTTP/1.1
    > Host: server.example.com
    > Connection: Upgrade, HTTP2-Settings
    > Upgrade: h2c
    > HTTP2-Settings: <base64url encoding of HTTP/2 SETTINGS payload>
    >
    < HTTP/1.1 101 Switching Protocols
    < Connection: Upgrade
    < Upgrade: h2c
    <
      [ HTTP/2 connection ...
    
  • For HTTPS (section 3.3), h2 protocol identifier in TLS-ALPN (RFC 7301) is used.

  • Immediately start with HTTP/2 connection preface, because of prior knowledge (section 3.4).

Now, the HTTP/2 client connection preface (section 3.5) might be the equivalent you are looking for, as the communication always begins with a sequence of 24 octets:

  • 0x505249202a20485454502f322e300d0a0d0a534d0d0a0d0a

    i.e. PRI *m HTTP/2.0\r\n\r\nSM\r\n\r\n

After that, the header fields are exchanged in the frames, using header compression (section 4.3):

Header lists are collections of zero or more header fields. When transmitted over a connection, a header list is serialized into a header block using HTTP header compression [COMPRESSION]. The serialized header block is then divided into one or more octet sequences, called header block fragments, and transmitted within the payload of HEADERS (Section 6.2), PUSH_PROMISE (Section 6.6), or CONTINUATION (Section 6.10) frames.

The HTTP/2 equivalents for several HTTP/1.1 requests and responses are illustrated in the examples on section 8.1.3, e.g.

 GET /resource HTTP/1.1           HEADERS
 Host: example.org          ==>     + END_STREAM
 Accept: image/jpeg                 + END_HEADERS
                                      :method = GET
                                      :scheme = https
                                      :path = /resource
                                      host = example.org
                                      accept = image/jpeg
Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122