Skip to content

HTTP/1.1 connection upgraded to HTTP/2 has old cowboy_req:version/1 #1613

@okeuday

Description

@okeuday

When using cowboy 2.10.0, a HTTP/1.1 connection that gets upgraded to HTTP/2 doesn't have its cowboy_req:version/1 data updated after the upgrade (i.e., 'HTTP/1.1' is returned instead of the expected 'HTTP/2'). Certain response headers are invalid for HTTP/2 use (based on curl use) like X-Content-Type-Options and X-XSS-Protection, so it is best to be aware of the current protocol used for the HTTP response headers. The version could be changed to 'HTTP/2' in cowboy_http:http2_upgrade/4 or cowboy_http2:init/12.

A way to replicate this problem is with CloudI/CloudI@f279724 using:

$ curl -v -v -v --http2 http://localhost:6464/cloudi/api/rpc/logging_status.erl
*   Trying ::1:6464...
* TCP_NODELAY set
* connect to ::1 port 6464 failed: Connection refused
*   Trying 127.0.0.1:6464...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 6464 (#0)
> GET /cloudi/api/rpc/logging_status.erl HTTP/1.1
> Host: localhost:6464
> User-Agent: curl/7.68.0
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 101 Switching Protocols
< connection: Upgrade
< upgrade: h2c
* Received 101
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Connection state changed (MAX_CONCURRENT_STREAMS == 4294967295)!
* http2 error: Invalid HTTP header field was received: frame type: 1, stream: 1, name: [X-Content-Type-Options], value: [nosniff]
* HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
* stopped the pause stream!
* Connection #0 to host localhost left intact
curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)

Using the curl argument --http2-prior-knowledge instead of --http2 doesn't cause this error, due to initiating the connection as HTTP/2 (no HTTP/1.1 upgrade occurs).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions