New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic helpers for HTTP/2 async pipelines #401
Conversation
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.
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. 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.
* Finish stream channel sequence continuation * 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start! Left some inline comments here and there
Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Outdated
Show resolved
Hide resolved
Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Outdated
Show resolved
Hide resolved
Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Outdated
Show resolved
Hide resolved
Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Outdated
Show resolved
Hide resolved
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift
Outdated
Show resolved
Hide resolved
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift
Outdated
Show resolved
Hide resolved
Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Outdated
Show resolved
Hide resolved
Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Outdated
Show resolved
Hide resolved
Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Outdated
Show resolved
Hide resolved
Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Outdated
Show resolved
Hide resolved
Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Outdated
Show resolved
Hide resolved
6fea265
to
e9c7f8e
Compare
737f00c
to
3a65355
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks super good already and I think we are getting quite close here!
Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Outdated
Show resolved
Hide resolved
let serverRecorder = InboundFramePayloadRecorder() | ||
serverRecorderContinuation.yield(serverRecorder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is safe. The InboundFramePayloadRecorder
is probably not Sendable
. What I meant with my previous comment was actually passing the continuation into this recorder so that the recorder is yielding whatever it records to it. (We might want to create a complete new type for this instead of botching the InboundFramePayloadRecorder
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I realized afterwards that this is probably not what you meant however I think it works as a convenient way to get the recorders out of the initializers and indicate when they're 'done'. I have made InboundFramePayloadRecorder
Sendable
to make it safe.
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift
Outdated
Show resolved
Hide resolved
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift
Outdated
Show resolved
Hide resolved
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift
Outdated
Show resolved
Hide resolved
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift
Outdated
Show resolved
Hide resolved
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift
Outdated
Show resolved
Hide resolved
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift
Outdated
Show resolved
Hide resolved
c31c408
to
34fe176
Compare
34fe176
to
43676e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of nits, but very nearly there!
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift
Outdated
Show resolved
Hide resolved
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Expose (as spi) generic helpers for HTTP/2 async pipelines
Motivation:
This PR is the first step in exposing APIs which surface HTTP/2 connections/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:
Channels
corresponding to inbound HTTP/2 streams in an async sequence.streamInitializer
on the common inbound initializer which is used to initialize inbound streams before yielding them to the continuation of streams.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.