Motivation: This is the beginning of removing the dependency on `nghttp2`. Modifications: I've added a new library target, `NIOHPACK`, which contains all the necessary pieces to implement HPACK encoding as specified in RFC 7541. There are unit tests exercising all the code and some additional edge cases around integer encoding, along with some performance tests for the Huffman encode/decode process. The latter currently takes longer to decode than to encode, which is worrying, but this is only really noticeable when encoding > 16KB strings as a rule; therefore I've decided not to pull out the optimization hammer just yet. Included in the unit tests are the inputs and outputs from all the examples in RFC 7541 and RFC 7540. I've tried to match the coding style from the repo, but some of my own idioms may have crept in here & there. Please let me know if you see anything wrong in that regard. Currently the static header table and Huffman encoding tables are implemented as Swift `let`s. For the static header table that's ok (only 62 entries), but the Huffman table is huge. I'm debating whether it's worth having that in a plain C file somewhere, but I'm not sure what the tradeoffs are vs. performance. Right now it seems to only affect compilation time, but I may be wrong. Result: In general, nothing will change: nothing in NIOHTTP2 is using this library yet. That part is what I'm working on now.
SwiftNIO HTTP/2
This project contains HTTP/2 support for Swift projects using SwiftNIO.
Please be aware that this project is currently in a beta state, and is subject to change. There are a number of current limitations in the project (see the Beta section for more details), and the API remains subject to change.
Building
swift-nio-http2 is a SwiftPM project and can be built and tested very simply:
$ swift build
$ swift test
Note, however, that you need nghttp2 installed and available to the linker. On macOS or other Darwin platforms, the easiest way to get nghttp2 is via Homebrew:
$ brew install nghttp2
For more recent Linux systems, nghttp2 may be available from your package manager. Otherwise, you may need to build it from source.
Beta
This project is currently in a beta state. The intention is to allow the wider SwiftNIO community to get early access in order to provide feedback and help guide the development of the HTTP/2 support.
The current version of these bindings has a dependency on nghttp2. This dependency is intended to be temporary: it was used to get the functionality up-and-running, but as time goes on nghttp2 should be scaled back, and eventually removed once all the functionality it provides has been replaced with Swift code.
Due to this early state, there are a number of limitations in the current bindings. Please be aware of them. The known limitations are listed below:
- Promises on control frame writes do not work and will be leaked. Promises on DATA frame writes work just fine and will be fulfilled correctly.
- No support for manual flow control window management, only automatic.
- No support for sending priority frames, and received priority frames will not be transmitted on the channel pipeline.
- No support for push promise frames, either sending or receiving.
- No low-level support for managing DATA frame boundaries: DATA frames may be interleaved and merged/split as necessary by nghttp2.
If you choose to use this project, please submit feedback and bug reports when you encounter problems or limitations.
Developing SwiftNIO HTTP/2
For the most part, SwiftNIO development is as straightforward as any other SwiftPM project. With that said, we do have a few processes that are worth understanding before you contribute. For details, please see CONTRIBUTING.md in this repository.