Skip to content

Conversation

@madsodgaard
Copy link
Contributor

@madsodgaardmadsodgaard commented Apr 30, 2021

Adds support for request-specific TLS configuration:
Request(url: "https://webserver.com", tlsConfiguration: .forClient())

apple/swift-nio-ssl#280 must be released, before this can be merged.

@swift-server-bot
Copy link

Can one of the admins verify this patch?

5 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@Lukasa
Copy link
Collaborator

@swift-server-bot add to allowlist

@madsodgaardmadsodgaard marked this pull request as ready for review May 5, 2021 15:43
Copy link
Contributor

@weissiweissi left a comment

Choose a reason for hiding this comment

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

Fab, thank you! This looks like a great start!

I left a few comments, mostly requesting changes that we don't accidentally merge the branch dependency.

self.port = request.port
self.host = request.host
self.unixPath = request.socketPath
iflet tls = request.tlsConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

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

@artemredkin should we add a test case that targets the pool directly here? Ie no actual connections?

@weissi
Copy link
Contributor

@madsodgaard hmm, weird 5.0 compiler warning (that we turn into errors):

[449/452] Compiling Swift Module 'AsyncHTTPClient' (15 sources) /code/Sources/AsyncHTTPClient/BestEffortHashableTLSConfiguration.swift:16:18: error: result of call to 'bestEffortEquals' is unused lhs.base.bestEffortEquals(rhs.base) ^ ~~~~~~~~~~ Build step 'Execute shell' marked build as failure 

Also, async-http-client uses automatic format checking with SwiftFormat. If you run SwiftFormat over the source, then the "soundness" part should pass.

@madsodgaard
Copy link
ContributorAuthor

@weissi Whoops, forgot a return statement 😅

@weissi
Copy link
Contributor

@madsodgaard also the API breakage checker detected an API breakage:

08:37:54 /* Removed Decls */ 08:37:54 Constructor HTTPClient.Request.init(url:method:headers:body:) has been removed 

Note that in Swift you cannot just add a new parameter (even if it has a default value) without breaking API. Instead of adding the tlsConfiguration: parameter with a default value, you'll need to add a new init with an extra (non-defaulted) parameter. The existing HTTPClient.Request.init(url:method:headers:body:) should then just call the new init with the extra parameter.

@weissiweissi requested a review from LukasaMay 6, 2021 12:48
@LukasaLukasa added the 🆕 semver/minor Adds new public API. label May 6, 2021

letrequiresTLS= key.scheme.requiresTLS
// Override optional connection pool configuration.
varkeyConfiguration= configuration
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm finding the naming here somewhat confusing: keyConfiguration is not derived from the key but from configuration, and then we override it with the TLS configuration from key.

I think it'd be nice to wrap this logic up into something written as a function that clarifies what it does (merges config from two sources, preferring config in the key to the general configuration.

I'm also a bit uncertain as to why this is necessary. Why isn't configuration already carrying this TLS config?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, should this merge perhaps be done at a higher level, say when we create the HTTP1ConnectionProvider? I am a bit nervous about having two separate configs from the perspective of the connection provider: it should always be creating the exact same connection each time.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

configuration is specific for the entire HTTPClient, so atm it passes down the configuration of client through all these methods. So, we need at some point to override the tlsConfiguration of it.

I moved the actual configuration "generation" to the place where we initialize the connection provider as you suggested, and added config(overriding:) to Key to retrieve key-specific configuration. Let me know, if this is better!

Copy link
Collaborator

@LukasaLukasa left a comment

Choose a reason for hiding this comment

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

Cool, this LGTM.

@LukasaLukasa requested a review from weissiMay 7, 2021 12:42
Copy link
Contributor

@weissiweissi left a comment

Choose a reason for hiding this comment

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

Fantastic, thank you very much!

@weissiweissi merged commit ca722d8 into swift-server:mainMay 7, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minorAdds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@madsodgaard@swift-server-bot@Lukasa@weissi