vapor / http

🚀 Non-blocking, event-driven HTTP built on Swift NIO.
MIT License
238 stars 65 forks source link

add http/2 server support (h2) #335

Closed tanner0101 closed 5 years ago

tanner0101 commented 5 years ago

This PR adds support for h2 aka HTTP/2 over TLS via ALPN. To enable HTTP/2 support, a new field supportVersions has been added to HTTPServerConfig.

let config = HTTPServerConfig(
    hostname: hostname,
    port: 8443,
    supportVersions: [.one, .two],
    tlsConfig: .forServer(...)
)

Here are the type declarations:

struct HTTPServerConfig {
    ...
    var supportVersions: Set<HTTPVersionMajor>
    ...
}

public enum HTTPVersionMajor: Equatable, Hashable {
    case one
    case two
}

When .two appears in the supportVersions set, the HTTP server will add h2 to its supported ALPN protocols list. If the HTTP/2 client decides to use h2, the server will configure HTTP/2 streams similar to HTTP/1.1 TCP connections: each stream will get its own delegate handler.

By default, HTTPServerConfig will specify support for both HTTP/1.1 and HTTP/2.

Todo:

penny-coin commented 5 years ago

Hey @tanner0101, you just merged a pull request, have a coin!

You now have 1113 coins.