Skip to content

Validate configuration at initialization - #107

Open
aryan-25 wants to merge 3 commits into
swift-server:mainfrom
aryan-25:validate-config-at-init
Open

Validate configuration at initialization#107
aryan-25 wants to merge 3 commits into
swift-server:mainfrom
aryan-25:validate-config-at-init

Conversation

@aryan-25

@aryan-25 aryan-25 commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Motivation

The required TLS contexts/configurations required to create the server channels are only constructed when NIOHTTPServer.serve is invoked. The problem with this is that these constructions can throw an error if the provided configuration was invalid.

We should not allow an invalid NIOHTTPServerConfiguration instance to be created in the first place: validation should occur during the initialization of NIOHTTPServerConfiguration.

Modifications

  • Added new validation methods to NIOHTTPServerConfiguration. These methods return SecureUpgradeContext/HTTP3Context (both introduced as part of this PR), which are now stored in NIOHTTPServerConfiguration.
    • These types contain the necessary contexts required to serve the respective channels. The serve method can directly use these properties and not invoke any throwing method relating to configuration.
  • Simplified the makeServerChannel method in NIOHTTPServer, as the logic that determines what server channels must be created can now be replaced by just checking whether the secureUpgradeContext and http3Context properties are nil or non-nil.
  • Some small general refactors to improve readability.

Result

Validation of NIOHTTPServerConfiguration now happens at initialization rather than during NIOHTTPServer.serve.

@aryan-25
aryan-25 requested a review from gjcairo August 3, 2026 16:01
@aryan-25 aryan-25 added the ⚠️ semver/major Breaks existing public API. label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚠️ semver/major Breaks existing public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant