0

I found that a get message header looks like:

:method: GET
:scheme: https
:authority: server.net
:path: /config
accept: */*
accept-encoding: gzip,deflate

What a connect message header should look like?

This example is from the RFC of http2:

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

I want to know the equivalent of the connect header in http2. In Http1 is:

CONNECT example.org:443 HTTP/1.1
Host: example.org:443
IGP
  • 37
  • 7
  • Are you referring to the `CONNECT` request message when using an HTTP proxy? – Matthew Apr 04 '22 at 13:57
  • yes, I try to send a connect message in http2 to the server and the server response is 400 (bad request) – IGP Apr 04 '22 at 14:07
  • Can you edit your post to provide what the actual request you're sending looks like? – Matthew Apr 04 '22 at 14:12
  • I edited it, it's looks like that – IGP Apr 04 '22 at 14:20
  • It's quite difficult to understand how to answer this question, as HTTP2 is a binary protocol, the format you've listed above is a plain-text representation of what is being transmitted. For connecting to a server as a client, you can read RFC at https://datatracker.ietf.org/doc/html/rfc7540#section-3 – Matthew Apr 04 '22 at 15:21
  • ok, you are right. My question is not very good. I should mention that I want to use nghttp2 library. I already read the RFC and I know that all http1.x/http2 messages are sent in binary format. My problem is that I cant understand the connect method in http2. I understand from RFC that the ":scheme" and ":path" pseudo-header fields MUST be omitted, so I put in the header just :method and :authority, and message looks in plain/text like: :method: CONNECT \n :authority: server.net – IGP Apr 04 '22 at 15:35
  • My server answers well at GET and POST messages, but at CONNECT not – IGP Apr 04 '22 at 15:37

1 Answers1

0

The format of the CONNECT method in HTTP/2 is specified in section 8.3.

With the formatting you used above looks like:

:method: CONNECT
:authority: proxy.net:8080

As specified, :scheme and :path must be omitted.

The HTTP/2 CONNECT method can also be used for bootstrapping other protocols (see for example WebSocket over HTTP/2), so that, additionally, the :protocol pseudo-header may also be present.

Remember however that this is only a textual representation of HTTP/2; the bytes that actually travel over the network are different since you must encode them using HPACK.

Unless you are actually writing an HTTP/2 implementation, it is better that you use existing libraries (available in virtually any programming language) to send HTTP/2 requests (of any kind): the libraries will take care of converting your CONNECT request into the proper bytes to send over the network.

sbordet
  • 16,856
  • 1
  • 50
  • 45
  • What should the header look like if the proxy has both a username and a password? – IGP Apr 05 '22 at 07:27
  • and what about Proxy-Authenticate and Proxy-Authorization? – IGP Apr 05 '22 at 09:09
  • Non-pseudo headers are present as usual, like in any HTTP request. They are HPACK-encoded like the pseudo-headers. The difference in a HTTP/2 `CONNECT` request is the absence of pseudo-headers that are otherwise mandatory, and the possible presence of the `:protocol` pseudo-header. – sbordet Apr 05 '22 at 11:42