Motivation:
Frames written from a child channel may not be written immediately by
the connection channel. For example, a DATA frame written on a stream
may be larger than the max frame size imposed on the connection and so
the connection channel will have to slice it into multiple frames. Or
the connection may not be writable and may delay the transmission of the
frame. This behaviour isn't currently observable but is useful to know
about.
Modifications:
- Add a frame delegate which is notified when certain frames are written
by the connection channel.
Result:
Users can observer when headers and data frames are written into the
connection channel.
Motivation:
To increase concurrency safety the NIOHTTP2 module should compile
without warning under strict concurrency checking.
Modifications:
- Add a few temporary internal helpers
- Annotate the pipeline helpers
Result:
Fewer concurrency warnings
Co-authored-by: Rick Newton-Rogers <rnro@apple.com>
In the async HTTP2 pipeline there is no way to account for the opening
and closing of streams. This PR adds a variant of
`configureAsyncHTTPServerPipeline` (HTTP2 upgrade channel) that allows
the user to pass in a `NIOHTTP2StreamDelegate` to be applied to the
HTTP2 channel if the upgrade occurs.
This is similar to #439 which did the same HTTP2 only channels.
Motivation:
Standardised formatting makes the project cleaner to look at and work
on.
Modifications:
Setup swift-format with the same settings as Swift-NIO
Result:
Common formatting throughout
Motivation:
Want to move away from legacy CI.
Modifications:
Add configuration and update code to use GitHub actions.
Result:
GitHub Actions can be used for basic CI.
Motivation:
`configureAsyncHTTP2Pipeline` doesn't allow a stream delegate to be
specified. As the async pipeline uses the "inline" stream multiplexer
there's no way to account for streams within the connection channel.
Modifications:
- Add a sync and async variants of `configureAsyncHTTP2Pipeline` which
accepts an optional stream delegate
- Rewrite the existing helpers in terms of the new one
Result:
Users can configure an async http pipeline with a stream delegate.
Motivation:
To address warnings revealed with
`.enableExperimentalFeature("StrictConcurrency=complete"),` in Swift 5.8
Modifications:
* Numerous protections of state in tests
* Make the multiplexer instances explicitly loop bound
* Update channel initializers to be marked as Sendable
* Mark error backing storage types as unchecked sendable
Result:
Better thread safety
* Mark generic async methods inlinable
Motivation:
Mark generic async methods inlinable where possible to improve performance.
Modifications:
Multiple methods marked `@inlinable`
Result:
Performance increase
We previously developed an async API for NIO HTTP/2 which was guarded under SPI. Now that the swift-nio async API is released we can reintroduce this code promoted to SPI.
This change introduces:
* `AsyncStreamMultiplexer` - an async variant of the HTTP/2 stream multiplexer which can be used to create outbound streams and provide access to an async sequence (`NIOHTTP2AsyncSequence`) of inbound streams
* New pipeline configuration functions (e.g. `configureAsyncHTTP2Pipeline`) to support the new async mode
* Bump minimum Swift version to 5.7
Motivation:
Now that Swift 5.9 is GM we should update the supported versions and
remove 5.6
Modifications:
* Update `Package.swift`
* Remove `#if swift(>=5.7)` guards
* Delete the 5.6 docker compose file and make a 5.10 one
* Update 5.10 alloc limits
* Update docs
Result:
Remove support for Swift 5.6, add 5.10
Motivation:
Remove dependency on SPI so that we can cut a release without
introducing dependency on code subject to change.
Modifications:
Remove all code which introduces a dependency on the NIOAsyncChannel SPI
Result:
Code inside SPI is removed
Motivation:
When adding in the SPI methods for exposing async sequences of HTTP/2
streams we moved the stream initialization to a subtly different
location so that it was easier to exfiltrate the outputs of those
initialization functions (such as protocol negotiation outputs).
In some cases this broke ordering expectations.
Modifications:
Yield the (optionally wrapped) channels as initializer outputs to the async stream
Result:
Changes only exist within SPI. Async inbound stream channel
initialization now matches previous behavior.
* Update to latest NIO with updated protocol negotiation API
Signed-off-by: Si Beaumont <beaumont@apple.com>
* fixup: Also replace deprecated get().waitForFinalResult()
Signed-off-by: Si Beaumont <beaumont@apple.com>
---------
Signed-off-by: Si Beaumont <beaumont@apple.com>
# Motivation
In my latest PR in NIO, I removed a bunch of API from the bootstrap methods to make the API easier to digest and reduce a number of duplicated code issues.
# Modification
This PR adopts the latest NIO changes and adapts the APIs in H2. More specifically, it removes the `NIOAsyncChannel` convenience methods and makes sure that everything aligns nicely with the proposes bootstrap APIs.
# Result
We now have the APIs in place to bootstrap a protocol negotiated H1/H2 server.
Motivation:
This continues the work to expose functionality which allows users to interact
with HTTP/2 connections via async abstractions and using structured
concurrency.
This work enables protocol negotiation between HTTP/1.1 and HTTP/2 in its most generic form.
Modifications:
Enable protocol negotiation between HTTP/1.1 and HTTP/2 using typed
negotiation results (`NIOProtocolNegotiationResult`) from the
`NIOTypedApplicationProtocolNegotiationHandler`.
In the HTTP/2 case the negotiation result will return the HTTP/2 connection
channel and the `NIOHTTP2Handler.AsyncStreamMultiplexer` which exposes
inbound streams as an iterable async stream.
Result:
Users will be able to set up negotiated HTTP/1.1 / HTTP/2 connections and
iterate over inbound streams.
Motivation:
Tweaking the formatting of the DocC comments enables syntax highlighting
for parameter names in Xcode
Modifications:
Whitespace changes, capitalisation changes and added a parameter
description for `indexing` in HOACKHeaders `replaceOrAdd`, `add`.
Result:
More readable DocC comments
* Add additional NIOAsyncChannel config
Motivation:
Recent additions to pipeline configuration did not expose some of the
`NIOAsyncChannel` configuration.
Modifications:
Expose `backpressureStrategy`, `isOutboundHalfClosureEnabled`.
I think specific naming and object encapsulation for these parameters should be discussed
later before SPI is removed and we review the API as a whole.
Result:
Pipelie helpers for `NIOAsyncChannel` expose `backpressureStrategy`, `isOutboundHalfClosureEnabled`.
* review comments, re-order parameters
* review comments
* param reordering, missing docs comments
* HTTP/2 pipeline NIOAsyncChannel pipeline config
Motivation:
This continues the work to expose functionality which allows users to interact
with HTTP/2 connections via async abstractions and using structured
concurrency.
We build atop of previous work to configure pipelines to deal with
HTTP/2 (with no protocol negotiation) and to wrap connection/stream
channels with `NIOAsyncChannel`s. This will allow users to iterate over
streams and HTTP2Frames.
Modifications:
Provide functions which configure channels and pipelines with the HTTP2
handler, expose a multiplexer for dealing with streams and wrap
connection and stream channels with `NIOAsyncChannel`s.
Result:
Users will be able to create and interact with HTTP/2 connections via
`NIOAsyncChannel`s. Because HTTP/2 is a negotiated protocol and we do
not yet handle it, this is of limited utility.
* review comments
* Update Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Co-authored-by: George Barnett <gbarnett@apple.com>
---------
Co-authored-by: George Barnett <gbarnett@apple.com>
There are a few places where bugs / poorly structured code crept in during the inline multiplexer work. This attempts to address some of them:
- overly long lines
- mis-named variables
- unnecessary use of generics in one case
* Store HTTP/2 inbound streams as async sequence
Motivation:
In preparation for exposing APIs which surface HTTP/2 connections and
streams using structured concurrency this PR introduces a store for
inbound HTTP/2 streams.
Modifications:
Define types and methods for storing generic types which wrap `Channels`
corresponding to inbound HTTP/2 streams in an async sequence.
Result:
The new types are not yet exposed, this work introduces part of the
framework for future functionality.
* Expose (as spi) helpers for H2 async pipelines
Motivation:
This PR is the first step in exposing APIs which surface HTTP/2 connections and
streams using structured concurrency. This PR exposes the most abstract
spelling of this concept, assuming no particular types/forms for the
types involved in the stream channel types.
Modifications:
* Store a generic `streamInitializer` on the common inbound initializer
which is used to initialize inbound streams before yielding them to
the continuation of streams.
* Expose pipeline configuration functions which assume HTTP/2 but
nothing else about sream channel types.
* Provide internal functions for creating streams without configuring
them. Configuring leads to activation so it can be helpful to allow
that step to be performed manually once any provided initialization
closures have beenn executed.
Result:
Adopters of the new SPI should be able to create outbound and deal with
inbound HTTP/2 stream channels using async streams.
Outside of SPI there should be no changes.
* use synchronous H2 multiplexer accessor
Motivation:
The `ChannelPipeline.SynchronousOperations.configureHTTP2Pipeline(...)`
method added to support synchronously setting up a pipeline to handle HTTP2 with the `StreamMultiplexer` embedded within the `NIOHTTP2Handler` erroneously retrieved the multiplexer via a `.wait()`. This is not permitted and will cause any code which executes it to deadlock.
Modifications:
The synchrounous operation now obtains the multiplexer via
`handler.syncMultiplexer()`
Result:
The code should not deadlock.
* update allocation counts
* ChannelPipeline H2 inline multiplexer conf funcs
Motivation:
To have parity with the legacy separate `HTTP2ChannelHandler`-`StreamMultiplexer` HTTP2 stream multiplexing model we provide channel pipelineconfiguration functions using the new inline multiplexer.
Modifications:
* New versions of `configureHTTP2Pipeline` and
`configureCommonHTTPServerPipeline` which set up the pipeline using
inline stream multiplexers
* Tests targeting the new functions ported from
`ConfiguringPipelineWithFramePayloadStreamsTests.swift`
Result:
New pipeline configuration conveniences for inline HTTP2 multiplexing
are available.
Motivation
Documentation is nice, and we can help support users by providing useful
clear docs.
Modifications
Add Docc to 5.6 and later builds
Make sure symbol references work
Add overview docs
Result
Nice rendering docs
Motivation:
With NIO 2.32.0 we broke the core NIO module up into modules that split
apart the POSIX layer and the core abstractions. As a result, this
package no longer needs to express a hard dependency on the POSIX layer.
Modifications:
- Rewrote imports of NIO to NIOCore.
- Added NIOEmbedded imports where necessary in tests.
- Note that the main modules still depend on NIO, which is necessary
for backwards-compatibility reasons. This dependency is unused.
Result:
No need to use NIOPosix.
Motivation:
Without knowing where an error was thrown it can be unnecessarily
difficult to work out the reasons an application ended up in an error
state.
Modifications:
- Add a 'file' string to each of the 'NIOHTTP2Errors' denoting the file
and line where an error was created
- Add static methods to create errors to 'NIOHTTP2Errors' defaulting
file and line, this is unfortunately necessary as defaulting file and
line in the `init` makes the defaulted and non-defaulted errors
indistinguishable, and the compiler will pick the one with fewest
defaulted values.
- Add equatable conformance manually so as to ignore 'file'
- Add backing storage to errors which no longer be stored in an existential
container
- Add 'CustomStringConvertible' conformance to the errors using backing
storage so that the 'file' is actually visible when converting the
error
- Deprecate the old `init`s
- Fix all deprecation warnings
Result:
- NIOHTTP2Errors carry a 'file' with them indicating where they were
created
Motivation:
As part of #214 we need to introduce new pipeline helpers to configure
the channel pipeline with the new handlers. This PR adds those helpers
and deprecates the old paths.
Modifications:
- Add pipeline helpers with the new streamID-less initializer
- Switch old pipeline helpers which provided codecs to use the new path
and codecs
- Duplicate SimpleClientServerTests and ConfiguringPipelineTests to add
frame payload based counterparts
- Deprecate older helpers and multiplexer init, delete tests which don't
hit deprecated paths (note: these still exist in the payload based
counterparts)
- Update Bench1Conn10kRequests to be payload based
Result:
- More 'FramePayload' based Tests
- Paths for creating an 'HTTP2Frame' based stream via
'HTTP2StreamMultiplexer' are now deprecated
Motivation:
Infow target window size constrains throughput. The default hardcoded 65535 is low for some use cases and so needs to be configrable. A TODO in the code stated 'Make configurable'.
Modifications:
- In HTTP2StreamMultiplexer, responding to a TODO where stream multiplexer creates a stream channel, created a multiplexr stored property to be used which is set in the default initilaizer.
- In HTTP2PipelineHelpers, added versions of configureHTTP2Pipeline(..) and configureCommonHTTP2ServerPipeline that require an activeTargetWindow arg.
Result:
Clients, such as GRPCClient, can configure pipelines with targetWindowSizes to their liking.
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation:
Applications might want to support H2 (when available) and HTTP1 (as a fallback).
The application logic should not change between the two versions of the protocol
and the code to configure support for both the protocols is boilerplate and can
be provided as an helper function.
Modifications:
This PR adds an helper function to configure HTTP1 or H2 pipelines according to
the protocol negotiated by the TLS handler.
Result:
Applications that need to support clients using both HTTP1 and H2 can
configure their channels by calling `configureCommonHTTPServerPipeline`,
which should reduce the boilerplate they have to write.
Co-Authored-By: Cory Benfield <lukasa@apple.com>
Motivation:
We attempted to use the NIO channel pipeline to spread out the HTTP/2
implementation across a number of channel handlers. Unfortunately, due
to the concerns of reentrancy it's not really safely possible to do this:
it's too easy for the pipeline ordering to become so confused that the
implementation ends up incorrect.
For this reason, we are going to squash together the three handlers that
provide a complete HTTP/2 protocol implementation into just one.
Modifications:
- Move the ConcurrentStreamsHandler and FlowControlHandler into the
HTTP2Handler.
- Update setup and test code accordingly.
Result:
More correct implementation
Motivation:
Rather than rely on users to get a bunch of stuff right when configuring
their HTTP/2 pipelines, it's helpful to insert the handlers in the right
order in a helper function.
Modifications:
Provide a helper configurator that inserts handlers correctly.
Result:
Easier to configure HTTP/2 pipelines.
* Updated to use SwiftNIO 1.10+ to gain access to HTTPHeaders internals.
* Add pure-Swift HTTP/2 protocol implementation.
Motivation:
Currently we use nghttp2 for our basic protocol implementation. This is
plenty workable, but provides us a number of limitations. It adds
complexity to our build system, provides us with external dependencies we
have little control over, limits our users' ability to express low-level
protocol semantics if they so wish, causes us to heap-allocate like crazy over
the lifetime of a connection, and brings a world of pain around reentrancy.
This set of limitations has motivated a desire to move away from using
nghttp2. This is a part of that dream.
Modifications:
- Add pure Swift protocol implementations.
- Test them.
Results:
Another step towards protocol independence.
* Initial basic parser code.
* Adding unit tests.
* Add NIOHTTP2FlowControlHandler
Motivation:
One of the things that nghttp2 used to do for us was to handle buffering
DATA frames until flow control allowed them to go out. For users that
want that behaviour, we need to replace the nghttp2 code with a new
ChannelHandler that can do this work.
Modifications:
- Added NIOHTTP2FlowControlHandler.
Result:
Users will have the same feature set as they did with nghttp2.
* Generate Linux test information.
* Documentation comment.
* Updated new tests from master to use new payload types.
* Updated following review.
Notable changes:
- Implemented unit tests for the ALTSVC (0xa) and ORIGIN (0xc) frame types.
- Additional DATA frames are synthesized to wrap individual payload chunks as they arrive. If the payload of a DATA frame with 4MB data arrives in 4 separate 1MB chunks, the decoder will emit 4 DATA frames, with only the last containing the END_STREAM flag (if that was set on the incoming frame).
- HEADERS / PUSH_PROMISE frames and any following CONTINUATION frames are now handled properly: header fragments from all frames are gathered up into a single buffer. Once a frame with END_HEADERS is encountered, the resultant accumulated buffer is sent for decoding along with the flags and stream ID of the original HEADERS / PUSH_PROMISE frame.
- HPACK encoders/decoders now live in the frame encoder/decoder types, rather than being attached to a stream.
* Updated Linux tests.
* Headers placed in relevant files.
* Add pure-Swift HTTP/2 protocol implementation.
Motivation:
Currently we use nghttp2 for our basic protocol implementation. This is
plenty workable, but provides us a number of limitations. It adds
complexity to our build system, provides us with external dependencies we
have little control over, limits our users' ability to express low-level
protocol semantics if they so wish, causes us to heap-allocate like crazy over
the lifetime of a connection, and brings a world of pain around reentrancy.
This set of limitations has motivated a desire to move away from using
nghttp2. This is a part of that dream.
Modifications:
- Add pure Swift protocol implementations.
- Test them.
Results:
Another step towards protocol independence.
* Revamped frame decoder state machine and API. Now uses separate input and output methods to manage multiple frames in a single buffer.
* Updated Linux tests.
* Bumped swift-nio version to 1.12.0 and updated `HTTPHeaders` -> `HPACKHeaders` conversion initializer to directly copy the buffer and map the header name/value indices.
* Set up HTTP2Parser in handlerAdded if the channel had been previously activated. (#36)
By setting up the handler in the handlerAdded hook, HTTP2Parser supports
being added dynamically in a channelRead event, after the channel has sent
the channelActive event.
(cherry picked from commit 88bd6d369a)
* Minor tweaks to get the tests passing
* Initial integration here
* Minor clearing up of the handler
* Get the tests compiling
* Fix header issues.
We now pass the frame parser to the various setting operations to let it
update the state. We also fixed some issues with specific settings.
* Remove ngthttp2-based impl, clean up stream ID
* Tests with new HTTP2StreamID
* Simple test cleanup
* Get remaining non-core tests passing
* Allow GOAWAY even when fully quiesced
* We don't buffer outbound frames any more
* Emit StreamClosed events on GoAway frame
* Notify stream creation and closure
* This test started failing
* Goodbye, C code! 🎉
* Send PING ACK automatically
* Updated based on PR feedback.
* Correctly handle 1XX responses
* Add SETTINGS_MAX_FRAME_SIZE support to flow controller
* Correctly account for flow control
* Define ConcurrentStreamsHandler
* Prepare for signalling connection state changes
* Better state change message propagation
* Refactor to use result with effect everywhere
* Don't lose flow control info on stream error
* Add basic flow control management to stream multiplexer
* Better pipeline in sample server
* Clean up some reentrancy concerns
* Move to Swift 5 and NIO 2
* Move to new Swift 5 for CI
* Allow wider range of choices of years
* Catch up to NIO 2 again
Motivation
The most common mechanism for negotiating HTTP/2 is to use ALPN.
We should support that.
Modifications:
Added a `ChannelPipeline` extension to configure a pipeline for
ALPN-based upgrade.
Added a property that indicates the ALPN tokens for HTTP/2 and
HTTP/1.1 use.
Result:
Should be possible to configure a channel pipeline for HTTP/2 work.