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 hooks for socket configuration #2918

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

John-Connolly
Copy link
Contributor

Description

Some user may need more advanced socket options for Vapors HTTP server. There is currently no way of specifying these options. This PR solves the issue by adding hooks for the server bootstrap. Many socket options such as SO_REUSEPORT need to be set before the server is started. Providing users with a configuration handler seems like a logical way of accomplishing this.

Example usage

 app.http.server.configuration.serverChannelOptionConfiguration = { serverBootstrap in
        serverBootstrap.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEPORT), value: SocketOptionValue(1))
 }

    app.http.server.configuration.childChannelOptionConfiguration = { serverBootstrap in
        serverBootstrap.childChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEPORT), value: SocketOptionValue(1))
 }

@@ -202,7 +212,9 @@ public final class HTTPServer: Server {
serverName: String? = nil,
reportMetrics: Bool = true,
logger: Logger? = nil,
shutdownTimeout: TimeAmount = .seconds(10)
shutdownTimeout: TimeAmount = .seconds(10),
serverChannelOptionConfiguration: @escaping (ServerBootstrap) -> ServerBootstrap = { bootstrap in return bootstrap },
Copy link
Member

Choose a reason for hiding this comment

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

I really don't like adding this niche use case to the initializer

Copy link
Member

@Joannis Joannis 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 it's a good addition, but I dislike the way it clutters the initializer for such a niche use case.

@John-Connolly
Copy link
Contributor Author

I think it's a good addition, but I dislike the way it clutters the initializer for such a niche use case.

@Joannis Thanks for the feedback. I tend to agree, 90 % of vapor users will not have a need to use this option. Thoughts on this being more akin to the customCertificateVerifyCallback that way the initializer doesn't need to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants