-
Notifications
You must be signed in to change notification settings - Fork 117
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
HTTPClientRequest: allow custom TLS config #709
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! I should have done this way earlier! I especially like that we add this property to the request itself and don't pass it as a function parameter!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't belongs to the HTTPRequest
. It is extra configuration and belongs into a separate type.
This belongs into tier 2 of #392.
Hang on, tier 3 can override anything from tier 2. The idea is:
For example (hypothetical API):
|
As discussed in #392, there seems to be no point in tier 3 if tier 2 is ~free to create. |
Convenience and you don't need to repeat everything. For example, I might want to ~always set a certain header in my tier 2 but in tier 3 I definitely want to add headers. Like
|
I agree with that, default headers on tier 2 are great. What I don't agree with is that tier 3 has override for everything in tier 2. Tier 3 should just be |
I think that's important. But also irrelevant for this PR. This PR brings back accidentally lost functionality when we added In the future when we pick up swift-http-types the whole nomenclature of what a "request" even is will change. Then we can discuss where the various configuration options can go. But this is the wrong place IMHO, we're just adding stuff back that we forgot before. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about this again I came to the conclusion that it doesn't hurt to add this before we implement the 3-tier architecture as we will likely deprecate HTTPClientRequest
anyway.
Minor nits, afterwards we are good to go from my side.
|
||
// For now, let's allow bad TLS certs | ||
request.tlsConfiguration = TLSConfiguration.clientDefault | ||
request.tlsConfiguration!.certificateVerification = .none |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets get ride of the force unwrap here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but that would hide issues. Force unwraps here are good because they'd catch that going wrong at the right place here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, nil
is the default configuration and it would be reasonable to normalise the input value to become nil after setting it to the default value.
Note that this shouldn't be an Optional property to begin with but that's the current API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that would not be reasonable, that would be user hostile. If this breaks, AHC is broken, let's not hide this
// For the second request, we reset the TLS config | ||
request.tlsConfiguration = nil | ||
do { | ||
let response2 = try await client.execute(request, timeout: .hours(99)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a bit long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disagree. Tests with timeouts that aren't ~forever really suck because at some point CI is slow and then you'll raise the timeout again. So you never quite know why it failed: Was CI slow or did it actually time out. If we set it to ~never (hours(99)
) then if it times out, it'll be killed by CI after the long CI timeout and we know that this is a true failure that needs to be fixed.
That means you'll have one timeout (the CI timeout) that is actually meaningful if it's breached. If everybody puts like .seconds(1)
or .seconds(10)
all over their tests then it requires constant thinking which leads to everybody just ignoring and restarting failed tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to use .hours(.max)
to make this clear but apple/swift-nio#2532
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this doesn't really help with unreasonably slow CIs as there are more timeouts with a default value. Also tests don't only run only CI but also locally and in compatibly suites. A reasonable time limit of 30 seconds is appropriate to be a good citizen if run in a compatibility suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any system that runs tests needs to already deal with tests taking forever. For example if you hit a deadlock. We shouldn't introduce another category of failures.
@dnadoba can we get this over the line please? |
@swift-server-bot test this please |
In the transition from
HTTPClient.Request
toHTTPClientRequest
we unfortunately lost some important functionality: Custom TLS configuration.The can be important to override on a per-request basis but more importantly it was the most significant step which allows us to unlock the 3-tier architecture (#392). For the 3-tier architecture it's very important to get rid of any top-level configuration.
This PR brings back the lost functionality.