Skip to content

Add configuration type for HTTP/1 server pipeline setup - #3746

Merged
aryan-25 merged 14 commits into
apple:mainfrom
aryan-25:server-pipeline-setup-configuration
Oct 19, 2026
Merged

aryan-25 merged 14 commits into
apple:mainfrom
aryan-25:server-pipeline-setup-configuration

Conversation

@aryan-25

@aryan-25 aryan-25 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Motivation:

NIOHTTP1.HTTPPipelineSetup contains helper methods which add HTTP/1 client/server handlers to the provided channel pipeline.

Over time, we have had to duplicate these methods when introducing a new configuration option in order to not break API.

As a result, there is now lots of duplication in NIOHTTP1.HTTPPipelineSetup and introducing more configuration options is very cumbersome. We should instead add a configuration type to solve this problem.

Modifications:

  • Added new configuration types named NIOHTTPServerPipelineConfiguration, and NIOHTTPServerPipelineSynchronousConfiguration.
  • Added a new pipeline setup helper method on ChannelPipeline and ChannelPipeline.SynchronousOperations that requires the configuration type as an argument.
  • Deprecated all existing helper methods on ChannelPipeline and ChannelPipeline.SynchronousOperations.

Result:

Better API.

@fabianfett fabianfett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the right direction. Thank you!

/// - ``outboundHeaderValidation``: `true`
/// - ``encoderConfiguration``: ``HTTPResponseEncoder/Configuration/init()``
/// - ``decoderLimitConfiguration``: ``NIOHTTPDecoderLimitConfiguration/init()``
public static var defaults: Self {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should move the default value config comments into the properties itself.

What is the benefit of the defaults static property. Why not just init()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've replaced the defaults property with a public init() now. See 1b8e7b2.

Comment on lines +1202 to +1216
fileprivate init(
pipeliningAssistance: Bool = true,
serverUpgrade: UpgradeConfiguration? = nil,
errorHandling: Bool = true,
outboundHeaderValidation: Bool = true,
encoderConfiguration: HTTPResponseEncoder.Configuration = .init(),
decoderLimitConfiguration: NIOHTTPDecoderLimitConfiguration = .init()
) {
self.pipeliningAssistance = pipeliningAssistance
self.serverUpgrade = serverUpgrade
self.errorHandling = errorHandling
self.outboundHeaderValidation = outboundHeaderValidation
self.encoderConfiguration = encoderConfiguration
self.decoderLimitConfiguration = decoderLimitConfiguration
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do we need this for? Why don't we use the normal init() and then set the properties accordingly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was to keep the diff minimal in all the existing helper methods. But I've removed this now. See #3746 (comment).

Comment on lines +1080 to +1086
position: position,
withPipeliningAssistance: configuration.pipeliningAssistance,
withServerUpgrade: configuration.serverUpgrade.map { ($0.upgraders, $0.completionHandler) },
withErrorHandling: configuration.errorHandling,
withOutboundHeaderValidation: configuration.outboundHeaderValidation,
withEncoderConfiguration: configuration.encoderConfiguration,
withDecoderLimitConfiguration: configuration.decoderLimitConfiguration

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should pass the new Config struct down here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in commit 09fd08f.

@aryan-25
aryan-25 requested a review from fabianfett October 15, 2026 12:26
public var upgraders: [HTTPServerProtocolUpgrader]

/// Called once the upgrade is complete, with the context of the handler performing the upgrade.
public var completionHandler: @Sendable (ChannelHandlerContext) -> Void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this doesn't need to be Sendable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in commit 5905b82.

/// the upgrade.
public init(
upgraders: [HTTPServerProtocolUpgrader],
completionHandler: @escaping @Sendable (ChannelHandlerContext) -> Void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this doesn't need to be Sendable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in commit 5905b82.

@aryan-25
aryan-25 requested a review from fabianfett October 16, 2026 18:05

@fabianfett fabianfett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AMAZING! Thanks for pushing through

@aryan-25
aryan-25 merged commit 108daca into apple:main Oct 19, 2026
64 of 66 checks passed
@aryan-25
aryan-25 deleted the server-pipeline-setup-configuration branch October 19, 2026 12:23
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.

2 participants