Opened 5 years ago

Last modified 2 months ago

#816 new enhancement

Allow h2c and HTTP/1.1 support on the same listening socket

Reported by: LPardue@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.9.x
Keywords: Cc:
uname -a:
nginx -V: 1.9.5


nginx 1.9.5 introduces support for HTTP/2.

If a user configures a h2c listening socket (e.g. listen port_num http2) only HTTP/2 connections via prior knowledge can be created; HTTP/1.1 clients will fail on the socket, preventing the use of HTTP Upgrade as a means of negotiating the protocol. In contrast, a h2 listening socket supports both HTTP/1.1 and HTTP/2 with negotiation of protocol via ALPN.

This ticket request an enhancement to allow simultaneous support of HTTP/1.1 and HTTP/2 on a plain TCP socket when using http2. Without the feature, we require the multiple listening ports for different protocols, which must be identified and managed out-of-band. The HTTP/2 spec accommodates support for multiple protocols on the same port. This enhancement could be achieved by implementing the following features (defined in section 3.2) :

  • Selection of protocol version by inspection of the request line
    • If the request line matches the HTTP/2 client connection preface then select HTTP/2 as the protocol for remainder of connection
    • else assume HTTP/1.1 for the remainder of connection. Standard request line validation rules are still applied. Note that if upgrade mechanism (below) is not implemented then ignore the request and just select HTTP/1.1.
  • Selection of protocol version using the HTTP Upgrade mechanism
    • If the client issues a valid h2c upgrade request
      • If the server supports h2c, respond with HTTP/1.1 101 Switching Protocols response and then select HTTP/2 as the protocol for remainder of connection
      • If the server does not support h2c, select the HTTP/1.1 protocol for remainder of connection and respond accordingly
    • If client issues an invalid upgrade request (e.g. h2) then ignore and select HTTP/1.1 protocol

For reference, this enhancement request tracks back to #808.

Change History (3)

comment:1 by AlekSi@…, 21 months ago

It would be great to have that feature.

comment:2 by, 18 months ago

Yes. It would be userful for for testing, https renders tcpdump dumps useless.

The current documentation mislead me. It says that http2 parameter work without TLS. And that is indeed true, but it still must not be enabled on port 80 because it does not work with HTTP 1.1, it returns binary data for a HTTP1.1 request.

Last edited 18 months ago by (previous) (diff)

comment:3 by daiglej@…, 2 months ago

Please implement!

Note: See TracTickets for help on using tickets.