Skip to content

Support HTTP/2 #582

@Nevon

Description

@Nevon

Before considering #468, which is a whole other kettle of fish, it would be great for Mappersmith to have a support story for HTTP/2.

But just providing an HTTP2 gateway might not be too useful to people, as they may not know whether the server supports HTTP/1.1 or HTTP/2 and expect both to be callable with "http". Instead I would suggest that the provided gateways, when possible, use HTTP/2 when available and fall back to HTTP/1.1 otherwise. Naturally it should be possible for a user to specify only using one protocol or the other, and simply failing if the server doesn't support that protocol, same as today.

Opportunistic HTTP/2 support

In order for a client and server to agree on a protocol version to use to communicate. There are basically two ways this can happen:

  1. When the server and client use TLS (i.e. they intend to use HTTPS) the protocol version is decided using Application Layer Protocol Negotiation (ALPN) where the client sends the protocol it supports in a TLS extension of the ClientHello message and the server responds with the protocol to use in the ServerHello. This is by far the most well-supported mechanism.
  2. If the server and client do not use TLS, the client can include an Upgrade header in a regular HTTP request, and if the server responds with a 101 Switching status, the connection will use http2 from that point onwards. I don't know that this method is supported by anything at all.

Current state

  • Fetch - I believe, but haven't verified this, that the browser implementation of fetch will use http/2 when available automatically. That being said, I haven't been able to find an authoritative source, and support may vary across browsers. The fetch implementation in node does not support HTTP/2 by default, but it is possible to enable, and I believe that in that case it will do ALPN to pick the protocol version to use.
  • HTTP - Does not support HTTP/2. There is an http2 module in node, but there's nothing that will do ALPN and pick the appropriate http module for you.
  • XHR - No clue but I highly doubt it supports HTTP/2.

Open questions

  • I don't know how tied to HTTP/1.1 the current gateway interface is, and whether it makes sense to make the existing HTTP gateway automatically switch between the different protocols, or if this should be a new HTTP2 gateway with the ability to fall back to HTTP/1.1.
  • HTTP/2 very much favors keeping long lived connections that are reused across man requests. I haven't looked into if Mappersmith can just delegate this responsibility down to the module implementing the protocol, or if there's any changes necessary within the gateways themselves to take advantage of this.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions