62 Commits
Author SHA1 Message Date
Cory Benfield f1d875433f Add support for Ubuntu 16.04's packaged nghttp2. (#29)
Motivation:

We'd done all our development against newer copies of nghttp2, that
behaved a bit differently. We should support Ubuntu's copy, at least
while nghttp2 is relevant to us.

Modifications:

- Shimmed over a version difference.
- Fixed the tests to stop relying on differences.
- Removed the Swift 4.0.3 dockerfiles as we don't support Swift
  4.0 anyway.

Result:

Users can build against Ubuntu 16.04's nghttp2 package.
2018-12-04 14:20:24 +00:00
Cory Benfield 38b8235868 Correctly activate child channels. (#27)
Motivation:

Child channels should not activate before their parents.

Modifications:

Delay activation if the parent channel is not currently active.
Activate during channelActive, if needed.

Result:

Easier to start HTTP/2 requests
2018-11-26 11:44:53 +00:00
Cory Benfield c0951893c7 Trailers sent on idle streams deserve to be sent too. (#25)
Motivation:

Due to nghttp2's weird data provider model, all trailers go through a
similar send path as data frames. This includes the fact that the data
sender can go "idle". If the data sender is idle, and the user sends
trailers, we don't bother to tell nghttp2 to ask us for more data,
so the trailers sit there forever, feeling sad.

Modifications:

- Correctly restart the data provider when sending data.

Result:

Trailers will be emitted when the stream is idle.
2018-11-21 11:42:22 +00:00
Tobias 4f8c857e5d Removes wrong return type documentation (#18) 2018-09-06 08:52:23 -04:00
Jim Dovey f2c2534d4c More Swift-y types for HTTP/2 frame, flags, and settings. (#16)
Motivation:

Prior to bringing in my HTTP/2 encoder/decoder, I think my implementations of HTTP/2 frame flags as `OptionSet`s and settings as an enum (i.e. existentials) make for a nicer API, and provide somewhat more information for the compiler to work with when optimizing.

Modifications:

- `HTTP2Frame.FrameFlags` is now an `OptionSet`.
- `HTTP2Frame.FramePayload` now supports all current HTTP/2 frame types, can return their on-wire identifier, and can return the set of `HTTP2Frame.FrameFlags` that the frame allows.
- `HTTP2Setting` is now an enum with associated values, and includes the SETTINGS_ENABLE_CONNECT_PROTOCOL value.
- Added `NIOHTTP2Errors.InvalidSettings` error, used when bad settings are encountered by decoder.
- Updated tests to use the new `HTTP2Setting` type.

Result:

Not a lot changes, beyond the in-memory layout of some things. All these types still have nghttp2 conversion methods, and all tests still run successfully.
2018-08-23 14:56:20 +01:00
Johannes Weiss 346af5be0e don't crash when client sends bad magic (#12)
Motivation:

We shouldn't just crash if the client sends bad magic.

Changes:

Send an error through the pipeline instead of crashing on bad client
magic.

Result:

fewer crashes
2018-08-16 15:29:14 +01:00
Cory Benfield 392b2e3228 Avoid crashing when MAX_CONCURRENT_STREAMS exceeds old cache size (#13)
Motivation:

Our dead stream cache should not cause us to crash when we can have more
active streams than the entire size of the cache. These things are
at least nominally unrelated.

Modifications:

Rewrote the code to avoid asserting that we'll always be able to shrink
down to the dead cache size.

Result:

Fewer crashes
2018-08-16 13:19:04 +01:00
Jim Dovey 6f8f523684 Implementation of HPACK encoding and header tables (#10)
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.
2018-08-16 09:51:13 +01:00
Cory Benfield b7085b6c0d Correctly discard only inactive streams. (#11)
Motivation:

Long-lived connections that have many inactive streams would cause
crashes. Crashes are, in my professional opinion, less than ideal
when they occur under expected usage cases.

Modifications:

- Fixed an inverted boolean check that would discard only *active*
  streams.
- Made the cached stream count configurable, removing a TODO.
- Added tests.

Result:

Fewer crashes, better software.
2018-08-15 21:26:50 +01:00
Cory Benfield 36321d080e Clean up tests. (#9)
Motivation:

Our tests were failing as a result of the previous commit changing the
HTTP/2 lifecycle.

Modifications:

Fired channelActive in a few tests, correctly propagated
channelInactive.

Result:

Tests should pass.
2018-05-20 11:18:25 +01:00
Cory Benfield d17462f586 Fix example server.
Motivation:

The example server had slowly bitrotted over time: some minor fixes were
needed.

Modifications:

I fixed it!

Result:

The example server works against a basic curl command.
2018-05-18 17:53:21 +01:00
Cory Benfield aee602c435 Add interface for creating channels from the client side. (#6)
Motivation:

While the HTTP2StreamMultiplexer could create channels in response to
inbound request streams on the server side, there was no interface for
creating channels locally.

That would make having a HTTP/2 client kinda tricky!

Modifications:

Added HTTP2StreamMultiplexer.createStreamChannel.

Result:

Possible to write HTTP/2 clients.
2018-05-18 17:26:12 +01:00
Cory Benfield 0a271b1cef Remove handlers from stream channel pipelines on shutdown. (#5)
Motivation:

When closing a stream channel, it must remove its channel handlers.

Modifications:

Call ChannelCore.removeHandlers on shutdown.

Result:

Handlers are removed on channel shutdown.
2018-05-18 14:05:12 +01:00
Cory Benfield c2d4a88b24 Flesh out HTTP2 to HTTP1 codecs. (#4)
Motivation:

Many users of HTTP/2 will not want to interact with the HTTP/2 protocol
directly, but instead to write generic HTTP applications on top of an
abstraction layer. These codecs provide part of that abstraction layer.

Modifications:

Added more codecs, fleshed them out, wrote many tests.

Result:

Easier application writing.
2018-05-18 11:35:26 +01:00
Cory Benfield e2ea2b88b9 Support read() 2018-05-17 11:58:25 +01:00
Cory Benfield bbcb593a6d Support buffered writes 2018-05-16 17:53:26 +01:00
Cory Benfield 5c5987e6ad Manage delayed stream channel setup 2018-05-16 15:37:41 +01:00
Cory Benfield 87cfe4897f Test stream-initiated closure. 2018-05-16 14:24:22 +01:00
Cory Benfield 861efdcd75 Remove closed channels from the map 2018-05-16 11:28:49 +01:00
Cory Benfield 59611cd174 Initial multiplexer testing 2018-05-15 17:36:43 +01:00
Cory Benfield 4acc76bfd7 Fire user events when streams are closed 2018-05-14 17:57:10 +01:00
Cory Benfield c7671bc982 Suppress PRIORITY frames 2018-05-14 15:35:09 +01:00
Cory Benfield 986922e01f Minor fixes 2018-05-14 14:52:28 +01:00
Cory Benfield e5d470daf6 Allow sending trailers 2018-05-14 13:39:15 +01:00
Cory Benfield 91349458ff Don't attach data for informational responses 2018-05-14 13:24:53 +01:00
Cory Benfield a5854839c7 Refactor state tracking for streams 2018-05-14 12:53:58 +01:00
Cory Benfield b7813bf908 Add hooks to data provider for trailers 2018-05-11 14:17:57 +01:00
Cory Benfield 493ba60314 CustomDebugStringConvertible for HTTP2StreamID 2018-05-11 10:56:34 +01:00
Cory Benfield 95b557d617 Fail writes when stream closed by rststream 2018-05-11 10:04:32 +01:00
Cory Benfield 7aa92fe7e2 Refactor error code to struct instead of enum 2018-05-10 17:35:46 +01:00
Cory Benfield 2d96d31212 Test automatic flow control 2018-05-09 17:53:41 +01:00
Cory Benfield ee9397f19e Be safe against reentrancy. 2018-05-09 15:52:46 +01:00
Cory Benfield e4111c2c51 Don't flush unnecessarily 2018-05-04 18:49:16 +01:00
Cory Benfield 3c6aa2c14c Be careful about flush handling. 2018-05-04 18:31:01 +01:00
Cory Benfield df9127952a Fail unflushed writes on EOF 2018-05-04 15:43:33 +01:00
Cory Benfield 9358a194ae Add support for PING frames 2018-05-04 14:46:42 +01:00
Cory Benfield e83baf083c Use the cached allocator 2018-05-03 17:27:10 +01:00
Cory Benfield ed7ce3e297 Confirm we can override default settings 2018-05-03 17:12:46 +01:00
Cory Benfield 409da26764 Allow passing default settings. 2018-05-03 17:01:26 +01:00
Cory Benfield 9b0b68e731 More expressive SETTINGS api 2018-05-03 16:23:43 +01:00
Cory Benfield 22e879d3cb Test breaching SETTINGS_MAX_CONCURRENT_STREAMS 2018-05-03 14:18:49 +01:00
Cory Benfield c937029ad4 Remove CONTINUATION (and so endHeaders).
We treat CONTINUATION frames as an implementation detail, which means the
endStream flag is also redundant. Let's remove both.
2018-05-03 10:48:54 +01:00
Cory Benfield 58284885d6 Remove warnings 2018-05-03 10:37:03 +01:00
Cory Benfield f4dcce5058 Test auto-splitting large DATA frames 2018-05-02 17:13:50 +01:00
Cory Benfield f82baa9378 Test stream quiescing 2018-05-02 15:36:05 +01:00
Cory Benfield 2cfbdb7ac5 Simple GoAway support 2018-05-02 14:42:55 +01:00
Cory Benfield c4933b6d08 Make stream IDs classes 2018-05-01 10:18:09 +01:00
Cory Benfield ca89364e1e Don't make HTTP/2 know about request/response head 2018-04-30 11:44:08 +01:00
Cory Benfield dddc12cd44 Cleanups 2018-04-30 10:26:25 +01:00
Cory Benfield 1ef32a0d3d Correct handling of stream IDs. 2018-04-27 15:40:18 +01:00