Skip to content
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

Add a variant of configureAsyncHTTPServerPipeline which takes a stream delegate #471

Merged
merged 5 commits into from
Nov 14, 2024

Conversation

adam-fowler
Copy link
Contributor

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.

/// be waited on to retrieve the result of the negotiation.
@inlinable
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public func configureAsyncHTTPServerPipeline<HTTP1ConnectionOutput: Sendable, HTTP2ConnectionOutput: Sendable, HTTP2StreamOutput: Sendable>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @adam-fowler, can you write a quick test that actually uses this function? Doesn't need to be complex, just something to confirm that it works and to ensure we won't regress it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops forgot to do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@adam-fowler
Copy link
Contributor Author

I've found I can't configure the HTTP1 channel either now. Would it be easier to make configureHTTP2AsyncSecureUpgrade public. Then I can provide the http1 and http2 channel setups I would prefer, without adding a mountain of new functions.

@Lukasa
Copy link
Contributor

Lukasa commented Oct 29, 2024

I'd like @FranzBusch to weigh in here if that's ok.

@FranzBusch
Copy link
Member

I've found I can't configure the HTTP1 channel either now. Would it be easier to make configureHTTP2AsyncSecureUpgrade public. Then I can provide the http1 and http2 channel setups I would prefer, without adding a mountain of new functions.

In general, I am not opposed to making that method public but it is also trivial to reimplement outside of this module. I would like to understand what you mean with "can't configure the HTTP1 channel" since there is an initialiser for incoming HTTP/1 connections in your API here.

@adam-fowler
Copy link
Contributor Author

I've found I can't configure the HTTP1 channel either now. Would it be easier to make configureHTTP2AsyncSecureUpgrade public. Then I can provide the http1 and http2 channel setups I would prefer, without adding a mountain of new functions.

In general, I am not opposed to making that method public but it is also trivial to reimplement outside of this module. I would like to understand what you mean with "can't configure the HTTP1 channel" since there is an initialiser for incoming HTTP/1 connections in your API here.

Actually you are right there, I can implement configureHTTP2AsyncSecureUpgrade outside of NIOHTTP2. I thought it used internal symbols but it seems it doesn't. Although I think it would be nicer for users of the library if they didn't have to.

Regarding the function I am adding here if the user wanted to configure the HTTP1 channel, it would require adding a bunch more parameters to this function ie all the parameters that configureHTTPServerPipeline currently takes. What do you think? Seems like quite a few extra parameters, I'm sure this could structured better.

@adam-fowler
Copy link
Contributor Author

So I got around this by duplicating configureHTTP2AsyncSecureUpgrade in the HB codebase so don't actually need this function anymore. Do you still want it? Or should I close this

@Lukasa
Copy link
Contributor

Lukasa commented Oct 30, 2024

I'm inclined to still want to take something in this space. @glbrntt was the last to work in this area of the codebase and so probably has the most informed opinion.

@adam-fowler
Copy link
Contributor Author

Well from my point of view making configureHTTP2AsyncSecureUpgrade public is the most useful thing that could be done. Then individuals can do the following

configureHTTP2AsyncSecureUpgrade { channel in
    setupHTTP1Channel()
} http2ConnectionInitializer: { channel in
    setupHTTP2Channel()
}

Which isn't far from the EventLoop API

channel.configureHTTP2SecureUpgrade(
    h2ChannelConfigurator: { channel in
        setupHTTP2Channel()
    },
    http1ChannelConfigurator: { channel in
        setupHTTP1Channel()
    }
)

Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense to add, but can you de-dupe some of the code with the other helper?

Sources/NIOHTTP2/HTTP2PipelineHelpers.swift Outdated Show resolved Hide resolved
@adam-fowler adam-fowler requested a review from glbrntt November 6, 2024 15:32
@adam-fowler adam-fowler force-pushed the http2-upgrade-stream-delegate branch from 5372cfd to bc8c387 Compare November 12, 2024 17:36
Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks a lot Adam!

@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Nov 13, 2024
@glbrntt
Copy link
Contributor

glbrntt commented Nov 13, 2024

There are a couple of formatting bits that need fixing up:

Sources/NIOHTTP2/HTTP2PipelineHelpers.swift:768:21: warning: [OmitExplicitReturns] 'return' can be omitted because body consists of a single expression
Sources/NIOHTTP2/HTTP2PipelineHelpers.swift:768:21: warning: [OmitExplicitReturns] 'return' can be omitted because body consists of a single expression
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift:610:25: warning: [OmitExplicitReturns] 'return' can be omitted because body consists of a single expression
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift:1:62: warning: [OmitExplicitReturns] 'return' can be omitted because body consists of a single expression
Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift:610:25: warning: [OmitExplicitReturns] 'return' can be omitted because body consists of a single expression

@glbrntt glbrntt enabled auto-merge (squash) November 13, 2024 14:05
@adam-fowler
Copy link
Contributor Author

@glbrntt seems like some of the actions failed because of timeouts when setting up

@glbrntt glbrntt merged commit 04a093d into apple:main Nov 14, 2024
42 checks passed
@adam-fowler adam-fowler deleted the http2-upgrade-stream-delegate branch November 14, 2024 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants