Opened 9 years ago

Closed 11 months ago

#816 closed enhancement (fixed)

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

Description

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 (5)

comment:1 by AlekSi@…, 5 years ago

It would be great to have that feature.

comment:2 by https://stackoverflow.com/users/733267/hontv%c3%a1ri-levente, 5 years 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 should not be enabled on port 80 because it does not work with HTTP 1.1, it returns binary data for a HTTP1.1 request.

Version 0, edited 5 years ago by https://stackoverflow.com/users/733267/hontv%c3%a1ri-levente (next)

comment:3 by daiglej@…, 4 years ago

Please implement!

comment:4 by Roman Arutyunyan, 11 months ago

This commit allows http/1 and h2c on the same cleartext socket:

https://hg.nginx.org/nginx/rev/08ef02ad5c54

comment:5 by Maxim Dounin, 11 months ago

Resolution: fixed
Status: newclosed

Committed and available in nginx 1.25.1, closing this. Thanks to all involved.

Note: See TracTickets for help on using tickets.