Swift NIO HTTP/2 Negotiation

The source code for NIOHTTP2Server currently contains the following comment:

// This example server currently does not know how to negotiate HTTP/2. That will come in a future enhancement. For now, you can
// hit it with curl like so: curl --http2-prior-knowledge http://localhost:8888/
  1. Is there a plan for supporting negotiation? I'm no expert on this but it seems there is a direct-from-TLS negotiation mechanism and an HTTP1 Upgrade header negotiation mechanism so this may involve cross-project coordination.

  2. Is this something that could be contributed by someone with a somewhat shallow understanding of the codebase?

Hi @George,

That’s a great question and would make an awesome contribution! This will indeed involve multiple NIO repositories and therefore I think it would be best suited in the swift-nio-examples repository similar to the also only partially complete http2-client example.

To get a server running that can do HTTP/1 over TLS and HTTP/2 with prior knowledge as well as upgrade from HTTP/1 you won’t need to have any in depth knowledge of the NIO codebase itself but you’ll need some more advanced NIO features like pipeline mutation. In the upgrade case, you’ll need to take out the HTTP/1 handlers and replace them with the HTTP/2 handlers instead.

To start with, I would recommend starting with HTTP/2 over TLS without the upgrade, knowing that it’s HTTP/2 via ALPN. Basically, exactly the counterpart to the http2-client mentioned above: still HTTP/2 with prior knowledge but over TLS. After that you could integrate HTTP/1 over TLS in the same server and as the last step you could add the upgrade. Also: this doesn’t all have to happen in one big PR, we can smart small and improve it over time :slight_smile:

I hope that makes some sense! Please don’t hesitate reaching out, @lukasa (the real HTTP/2 expert) and I are here to help!