Skip to content

Refactor URL component extraction #485

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

Merged
merged 4 commits into from
Nov 26, 2021
Merged

Conversation

karwa
Copy link
Contributor

@karwa karwa commented Nov 19, 2021

This is currently split across 4 functions (well, 3 functions and an initialiser). It's much easier to understand how AHC understands these URL formats if it happens in a single function (especially since schemes like http+unix are not standardised).

Additionally, this rejects empty HTTP hostnames, as they are invalid per the spec, and empty socket paths, since they are meaningless.

@swift-server-bot
Copy link

Can one of the admins verify this patch?

6 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?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@dnadoba
Copy link
Collaborator

dnadoba commented Nov 19, 2021

@swift-server-bot test this please

@fabianfett fabianfett requested a review from Lukasa November 20, 2021 12:36
@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Nov 22, 2021
Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Yup, this makes sense, thanks. Do you mind very briefly adding tests that validate that empty socket paths are now rejected?

@Lukasa
Copy link
Collaborator

Lukasa commented Nov 22, 2021

@swift-server-bot add to allowlist

self.socketPath = try self.kind.socketPathFromURL(url)
self.uri = self.kind.uriFromURL(url)

(self.kind, self.host, self.socketPath, self.uri) = try Self.deconstructURL(url)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great work! Thank you!

Would you mind returning the scheme and port in deconstructURL(_:) as well?
scheme is already a stored property in HTTPClient.Request but port not.

public var port: Int {
return self.url.port ?? (self.useTLS ? 443 : 80)
}

However, I don't mind adding port as another stored property. This would allow us to better reuse this functionality in the upcoming new HTTPClientRequest for async/await support as described in this proposal:
https://github.com/swift-server/async-http-client/blob/96872470475f18a5667fbf681e2e0f67ad8a0110/docs/async-await.md#new-httpclientrequest-type

Copy link
Collaborator

Choose a reason for hiding this comment

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

@karwa friendly ping 🙂
I would like to use your changes soon. Do you have any estimate when you have time to work on this again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll address the comments now and update the patch

@karwa
Copy link
Contributor Author

karwa commented Nov 25, 2021

OK, I've added the test as @Lukasa requested, and deconstructURL now extracts the scheme and port number as @dnadoba requested.

The tuple return type is rather large and should be a named type, but I suppose that's basically what the new async design's Request type will be.

Copy link
Collaborator

@dnadoba dnadoba left a comment

Choose a reason for hiding this comment

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

Thanks a lot! One small change and we are good to go from my side.
CI is currently flaky because I turned parallel testing on. Fix is on its way (#498) so don't worry if you see any test in HTTPClientSOCKSTests failing.

Copy link
Member

@fabianfett fabianfett left a comment

Choose a reason for hiding this comment

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

This is a great change! Thanks!

@dnadoba dnadoba merged commit f2c2f73 into swift-server:main Nov 26, 2021
@karwa karwa deleted the url-extract branch November 26, 2021 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants