Commit Graph
230 Commits
Author SHA1 Message Date
aryan-25 b6571f3db4 Add a server connection manager (#532)
Motivation:

`NIOHTTP2Handler` currently does not support graceful shutdown because
it does not action upon a `ChannelShouldQuiesceEvent` event. See issue
https://github.com/apple/swift-nio-http2/issues/336.

Per the
[comment](https://github.com/apple/swift-nio-http2/issues/336#issuecomment-2252862397)
on that issue,
[`gRPC-swift-nio-transport`](https://github.com/grpc/grpc-swift-nio-transport)
implements this functionality in a separate channel handler, named
[`ServerConnectionManagementHandler`](https://github.com/grpc/grpc-swift-nio-transport/blob/main/Sources/GRPCNIOTransportCore/Server/Connection/ServerConnectionManagementHandler.swift).
We should introduce this to this repo too.

Modifications:

- Added `ServerConnectionManagementHandler` from
`gRPC-swift-nio-transport` with some slight modifications such as
removing gRPC-specific functionality like policing client pings.
- Added a new `configureAsyncHTTP2Pipeline` helper, which takes a
connection manager configuration as an argument and sets the
connection manager up alongside `NIOHTTP2Handler`.

Result:

Addresses issue https://github.com/apple/swift-nio-http2/issues/336.
2026-02-18 08:08:55 +00:00
Fabian Fett 979f431f1f Optimize HTTP2ToHTTP1 client codec to reduce empty data frames (#535)
The codec now caches the most recent outbound frame and only writes it
on flush or when receiving `.end`. This lets us set `endStream=true` on
the final data or headers frame instead of sending a separate empty data
frame.

Changes:
- Introduced `PendingFrameWrite` to cache frame payload and promise
- Modified `processOutboundData` to return optional frames instead of
writing immediately
- Added `flush()` method to both client codecs to handle cached writes
- Promise merging ensures correct completion notification when combining
frames
2026-02-10 10:16:27 +00:00
George Barnett 5e9e99ec96 Add a frame delegate (#522)
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.
2025-07-18 15:30:36 +01:00
Gus Cairo f0e94525a7 Add GlitchesMonitor (#518)
Add a `GlitchesMonitor` that will terminate a connection if too many glitches are triggered.
See https://github.com/HTTPWorkshop/workshop2024/blob/main/talks/1.%20Security/glitches.pdf for details.
2025-07-16 16:19:40 +01:00
George BarnettandRick Newton-Rogers 159ef997b2 Strict concurrency for tests (#507)
Co-authored-by: Rick Newton-Rogers <rnro@apple.com>
2025-03-31 13:38:26 +01:00
George Barnett 1251530b26 Allow max reset stream frames to be configured (#494)
Motivation:

The maximum number of recently reset stream frames to track is limited
to a fixed value of 32. This should be configurable.

Modifications:

- Add it to the connection config and propagate it through

Result:

- Resolves #493
2025-02-28 13:54:05 +00:00
George Barnett 124e859117 Better handle new streams when server is quiescing (#481)
Motivation:

When the server is in the locally quiescing state and a client attempts
to open a new stream, the connection state machine treats receiving the
headers as a connection error. This results in the connection being
closed and in-flight requests being failed.

This can happen because of the inherent race between the server sending
a GOAWAY frame and the client receiving it, during which time the client
can open a stream not knowing it's doomed to failure.

Rather than the server treating this as a connection error, it should
reject the stream with a RST_STREAM frame and emit a stream error.

Modifications:

- Emit a stream error when receiving HEADERS in the locally quiesced
state

Result:

Better handling of new streams when the server is quiescing
2025-01-20 18:01:49 +00:00
Gus Cairo 170f4ca06b Don't fail closeFuture when an error occurs on closing (#487)
Strictly speaking, a `close` operation can't really fail (except when
the closing mode isn't supported or the channel is already closed). Even
if an error is encountered while closing a channel, or if an error
caused the channel to be closed, the end result is the same: the channel
will be closed.

In this case in particular, when streams are closed from the client
(i.e. by sending a RST_STREAM frame) the `HTTP2StreamChannel` would fail
the channel's `closeFuture`. This isn't appropriate however, as the
channel is successfully closed.

This change stops failing the stream channel's `closeFuture`. Instead,
if the close happens uncleanly, the error will be fired down the
pipeline and the `close` method's promise will be failed.
2024-12-16 15:38:34 +00:00
Rick Newton-Rogers 2083f5d7e8 Enable MemberImportVisibility check on all targets (#486)
Enable MemberImportVisibility check on all targets. Use a standard
string header and footer to bracket the new block for ease of updating
in the future with scripts.
2024-12-11 15:38:17 +00:00
Gus Cairo 1879e72392 Finish multiplexer's inbound streams in more cases (#483)
## Motivation
Currently, the multiplexer's inbound streams stream is finished only
when the channel becomes inactive.
There are some scenarios in which the channel may be closed before it
has a chance to become active, and the stream will never be finished.
This can cause any users iterating over the stream to hang.

## Modifications
This PR finishes the inbound streams stream when a connection error is
fired, and when the handler is removed.

## Result
Fewer bugs.
2024-11-15 10:45:47 +00:00
Adam Fowler 04a093d050 Add a variant of configureAsyncHTTPServerPipeline which takes a stream delegate (#471)
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.
2024-11-14 10:27:14 +00:00
finagolfin 1959f760e7 Import new Android overlay instead in the tests (#479)
I added the `Bionic` import this summer in #448 and the compiler
accepted it then, but it started erroring a couple months later without
this full Android overlay, so add that instead.
2024-10-30 15:55:49 +00:00
Peter Adams 1118370ec4 Apply swift-format changes and CI (#472)
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
2024-10-29 13:09:54 +00:00
Peter Adams 31c8609808 Drop support for Swift 5.8 (#470)
Motivation:

Only the last 3 versions of Swift are supported.

Modifications:

Update the Swift tools version in Package.swift.
Remove code which can now never be compiled.
Remove legacy docker configuration.

Result:

Only Swift 5.9+ supported.
2024-10-23 15:06:45 +01:00
George Barnett 6693a60432 Propagate ChannelShouldQuiesceEvent to child channels (#464)
Motivation:

NIO has a 'ChannelShouldQuiesceEvent' which channels can listen for in
order to know when they should quiesce. This is typically used to
initiate a graceful shutdown of an HTTP/2 server. However, child
channels aren't notified of this event so HTTP/2 servers must keep track
of streams separately in order to notify them when the server is
quiescing.

Modifications:

- Propagate the `ChannelShouldQuiesceEvent` to child channels

Result:

Child channels can watch for `ChannelShouldQuiesceEvent`s
2024-09-18 07:02:53 +01:00
Clinton Nkwocha 376312d334 Handle race condition between sending GOAWAY and HEADERS (#457)
Motivation:

A potential race exists between a server sending a GOAWAY frame and a
client opening a new stream (i.e., sending a HEADERS frame before
receiving an already sent GOAWAY frame). If there are no open streams
when the server sends the GOAWAY frame, the connection state on the
server transitions to being fully quiesced, which throws a connection
error on receipt of a HEADERS frame.

Modifications:

- Adjust the connection state machine on the server to throw a stream
error (instead of a connection error), and consequently, send a
RST_STREAM frame to the client.

Result:

This condition will be treated as a stream-level error instead.
2024-09-06 11:59:15 +01:00
Clinton Nkwocha 9f6d865c81 Accept PING frames even when fully quiesced (#455)
Motivation:

When the connection is fully quiesced, an endpoint responds with a
connection error when it receives or tries to respond to a PING frame.
This behaviour is unnecessary.

Modifications:

- Adjust `HTTP2ConnectionStateMachine` to successfully receive and send
PING frames even when the connection is fully quiesced.

Result:

When the connection is fully quiesced, an endpoint will treat receipt
and sending of a PING frame as it would when the connection is active.
2024-08-30 03:50:01 -07:00
aryan-25 35b0b8f7e5 Fix bug where client ignores HEADERS frames on open stream when locally quiescing (#445)
Motivation:

Currently, HEADERS frames are ignored by the client on a client-initiated stream after the client sends a GOAWAY.

As per [Section 6.8 (GOAWAY) in RFC 9113](https://httpwg.org/specs/rfc9113#GOAWAY):
_"Once the GOAWAY is sent, the sender will ignore frames sent on streams **initiated by the receiver** if the stream has an identifier higher than the included last stream identifier."_

In this case, the client (sender) should **not** ignore the HEADERS frame as the stream is initiated by the _client_, not the receiver.

Modifications:

Fixed the condition in the `receiveHeaders` function (given `LocallyQuiescingState`) in `ReceivingHeadersState.swift` to work for _both_ the client and server roles -- before this change, the condition is only correct when `self.role == ConnectionRole.server`

Result:

HEADERS frames are not ignored by the client on a client-initiated stream when locally quiescing.
2024-07-18 06:55:30 -07:00
a2b4d284f4 Make HEADERS frame payload non-indirect (#428)
* Make HEADERS frame payload non-indirect

Motivation:

In previous patches we shrank the size of HTTP2Frame by
making various data types indirect in the frame payload.
This included HEADERS, which is unfortunte as HEADERS frames
are quite common.

This patch changes the layout of the HEADERS frame to remove the
indirect case.

Modifications:

- Move END_STREAM into an OptionSet.
- Turn the two optional bits into flags in the aforementioned
    OptionSet
- Replace the properties with computed properties.
- Remove the indirect case

Result:

HEADERS frames are cheaper.

* Update alloc limits

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
Co-authored-by: Gustavo Cairo <gus.cairo@apple.com>
2024-07-17 09:00:49 -07:00
finagolfin cbdbc9c808 Use Bionic module from new Android overlay in Swift 6 instead (#448) 2024-07-15 00:15:53 -07:00
Clinton NkwochaandGeorge Barnett d629013a6e Reject long sequences of CONTINUATION frames (#443)
* Reject long sequences of CONTINUATION frames

Motivation:

Long sequences of CONTINUATION frames can be used to mount attacks by attempting to get a remote peer to consume large amounts of memory.

Modifications:

- Add a limit to the number of sequential CONTINUATION frames that can be received. This limit is configurable by users at the NIOHTTP2Handler level and has a default value of 5. When this limit is exceeded, the recipient responds with a GOAWAY frame and an "Enhance Your Calm" error of a newly created type `ExcessiveContinuationFrames`.

Result:

Long sequences of CONTINUATION frames are now rejected by the recipient.

* Refactor implementation

* Minor adjustments

* Implement adjustments

- Refactor implementation
- Revert unnecessary diffs

* Implement adjustments

- Change `public let maximumSequentialContinuationFrames` to `public var`.
- Refactor implementation.

* Implement minor adjustments

* Store the default `maximumSequentialContinuationFrames` in a `private static let`

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2024-07-04 14:13:49 +01:00
Eric Rosenberg 6af2cf64cb Implement RFC8441 Extended CONNECT (#441)
Implement RFC8441 Extended CONNECT
2024-06-24 08:33:39 +01:00
George Barnett 8d8eb60992 Add a variant of configureAsyncHTTP2Pipeline which takes a stream delegate (#439)
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.
2024-05-16 14:12:57 +01:00
Johannes Weiss 356a3af761 test compiler not language version (#440) 2024-05-09 12:59:05 +01:00
Rick Newton-RogersandCory Benfield 69e838fb22 Remove precondition: yielding to terminated AsyncSequence (#432)
Motivation:

If a task iterating over inbound streams using the new async API is
cancelled then it can lead to the process crashing as we hit a
precondition which guards against yielding to a terminated
NIOHTTP2AsyncSequence.

Modifications:

Remove the precondition.

Result:

The code no longer crashes, instead it silently drops the yielded value.

Doing more than this such as closing the connection requires rethinking
more of the API.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-12-20 14:57:41 +00:00
Si Beaumont 94ab10b5af Use explicit 64-bit UInt64 to support 32-bit platforms (#430) 2023-12-18 15:11:15 +00:00
Si Beaumont 28a91a3b09 Add missing availability guards in tests (#429)
## Motivation

Some of the test code was missing availability guards for Apple platforms, resulting in build failures for these platforms, e.g.

```
error: 'NIOAsyncTestingChannel' is only available in iOS 13.0 or newer
         var clientChannel: NIOAsyncTestingChannel!
```

## Modifications

Add missing availability guards. I've tried to keep them as scoped as possible. Some test suites used these as class properties, so these got a guard at suite level.

## Result

Tests can now build and run on iOS and other Apple platforms.
2023-12-15 18:02:18 +00:00
Rick Newton-Rogers 285e444b49 Sendability warnings (#417)
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
2023-11-01 14:36:38 +00:00
Franz Busch 3bd9004b9d Remove retroactive CustomDebugStringConvertible conformance in tests (#425)
# Motivation
We had a retroactive `CustomDebugStringConvertible` conformance to `ByteBufferView` in one of our tests harnesses which caused compiler errors in the latest nightlies.

# Modification
This PR removes the retroactive conformance.

# Result
No more compiler errors.
2023-10-25 08:07:40 -07:00
Rick Newton-Rogers 462ded73ad HTTP/2 Async API (#424)
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
2023-10-25 15:49:16 +01:00
Rick Newton-Rogers 3798fe5f15 Merge pull request from GHSA-qppj-fm5r-hxr3
* Limit rate of permitted RST frames

Motivation:

Large number of stream reset frames may be used as a DoS (Denial of
Service) vector in an attempt to overload the CPU of the handling server.

Modifications:

Introduce an additional DoS heuristic which evaluates the rate of
incoming stream reset frames. If the rate exceeds that which is
permitted then the connection is closed and a `GOAWAY` issued.

The allowed rate is configurable but defaults to 200 resets within 30
seconds. This should be acceptable for most applications.

Result:

Excessive reset frames result in the connection being closed.

* review comments

* further review comments

* add integration test
2023-10-10 13:00:57 +01:00
Rick Newton-Rogers 2140160e95 Remove dependency on SPI (#419)
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
2023-10-04 13:21:17 +01:00
Rick Newton-Rogers 8275314739 Async stream initializers order matches existing (#415)
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.
2023-09-11 14:46:40 +01:00
George Barnett 92afa4fa84 Delay stream creation until the next loop tick (#416)
Motivation:

A recent change allowed stream creation to run immediately if the caller
was on the correct event loop. Normally that's fine, however, it opens
up a code path where streams can become activated twice which leads to a
crash.

Modifications:

- Delay stream creation until the next loop tick
- Add a loop tick to tests which now require it

Result:

Avoid re-entrantly activating streams twice.
2023-08-23 11:28:07 +01:00
Si Beaumont 2bf57336ec Update to latest NIO with updated protocol negotiation SPI (#414)
* 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>
2023-08-08 14:36:51 +01:00
Quirin Schweigert 493897c474 Fix parent channel read() call on HTTP2StreamChannel initialization causing incorrect order of inbound HTTP2Frames (#413)
Motivation:

Make sure the order of `HTTP2Frame`s that are fired through the pipeline of a `HTTP2StreamChannel` by `HTTP2CommonInboundStreamMultiplexer` is correct when a `read()` call on the parent channel synchronously causes further frames to be processed.

Modifications:

Reorder calls in `HTTP2CommonInboundStreamMultiplexer.receivedFrame(frame:context:multiplexer)` so that initial header frame is buffered and processed first.

Result:

Resolves #410 and makes newly added test case `HTTP2StreamMultiplexerTests.testMultiplexerFiresInitialFramesInCorrectOrder()` pass.
2023-07-28 09:15:01 +01:00
Franz Busch 7e4dd147b0 Adopt latest AsyncChannel changes (#411)
# 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.
2023-07-26 13:48:25 +01:00
Rick Newton-Rogers 044339de7b HTTP/2 negotiated connection pipeline config (#408)
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.
2023-07-12 11:07:53 +01:00
Rick Newton-Rogers 188fa9ba27 adopt NIOAsyncChannel.Configuration (#409)
Adopt NIOAsyncChannel.Configuration as the NIO SPI changed
2023-07-11 16:43:41 +01:00
Rick Newton-RogersandGeorge Barnett e0ffed790a HTTP/2 pipeline NIOAsyncChannel pipeline config (#403)
* 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>
2023-07-04 06:21:57 +01:00
Rick Newton-Rogers b9fe8f57a0 Inline http2 fixups (#402)
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
2023-07-03 03:54:55 -07:00
Rick Newton-Rogers 83c04dbddb Generic helpers for HTTP/2 async pipelines (#401)
* 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.
2023-07-03 11:19:04 +01:00
brennoandCory Benfield 87e96ed89b Replace os() with canImport(Darwin) (#399)
* Replace os() with canImport(Darwin)

* Removed compilation condition since it'll be always true

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-06-23 03:28:57 -07:00
finagolfin f509541022 Fix test for HPACKHeader.removeAll(keepingCapacity:) on Android (#395)
Motivation:

Get this test passing on Android

Modifications:

Change the capacity to whatever it originally was, rather than a hard-coded value.

Result:

Resolves #394 and the test now passes
2023-05-19 13:02:22 +01:00
Fabian Fett 145eec4e4f Add HPACKHeader.removeAll(keepingCapacity:) (#393)
In scenarios, in which we want to send lots of small HTTP/2 requests, we want to reuse a single HPACKHeaders object as often as we can. To support this we should have a removeAll(keepingCapacity:) method.
2023-05-17 02:09:06 -07:00
Si Beaumont 428b0f3551 Drop support for Swift 5.5 (#392)
Motivation:

Now Swift 5.8 is released, we are dropping support for 5.5, in line with the usual support 

Modifications:

- Remove `Package@swift-5.5.swift`.
- Remove `LinuxMain.swift` and `generate_linux_tests.rb` script.
- Remove use of `generate_linux_tests.rb` from CI check.
- Update README.

Result:

No functional change, but Swift 5.5 is no longer supported.
2023-04-17 13:27:31 +01:00
Rick Newton-Rogers 7f82cc3d64 Replace estimatedFrameSize with flowControlledSize (#387)
Motivation:

`estimatedFrameSize` aims to estimate the number of bytes a frame will
use on the wire. It includes the 9-octed frame header and is currently
used for flow control estimates but according to spec it shouldn't
include those 9 bytes https://www.rfc-editor.org/rfc/rfc9113.html#section-6.9.1

Modifications:

Replace `estimatedFrameSize` with `flowControlledSize` which ignores the
9-octed frame header and update tests.

Result:

Flow control calculations should be more accurate
2023-04-06 15:08:11 +01:00
Rick Newton-Rogers 78176ba277 Remove NIOHTTP2StreamDelegate Sendable requirement (#384)
Motivation:

Remove `NIOHTTP2StreamDelegate` `Sendable` conformance requirement.
This wasn't needed in the first place because `NIOHTTP2Handler`
is not `Sendable`, therefore it never leaves the thread on which it is
created.

The delegate may still be `Sendable` depending on the implementation
but it is not a strict requirement.

Modifications:

Remove NIOHTTP2StreamDelegate Sendable requirement

Result:

Sendable is no longer required for NIOHTTP2StreamDelegate conformance
2023-04-05 16:40:55 +01:00
Rick Newton-Rogers 795c1d4a48 Expose a functional NIOHTTP2StreamDelegate (#382)
Motivation:

Allow handlers in the pipeline to be notified when an HTTP2 stream is created or
closed.

Modifications:

Store an instance of a `NIOHTTP2StreamDelegate` on the `NIOHTTP2Handler`
and `InlineStreamMultiplexer` so that it may be called when streams are
created or closed.

Added tests.

Result:

`NIOHTTP2Handler`s init'd with a `streamDelegate` will now call into
that delegate's `streamCreated` and `streamClosed` functions.
2023-03-31 09:14:18 +01:00
Rick Newton-Rogers a32335d23e ChannelPipeline H2 inline multiplexer conf funcs (#381)
* 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.
2023-03-30 17:34:13 +01:00