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

Fix leading slash issue in relative URL requests #747

Merged

Conversation

aryan-25
Copy link
Contributor

@aryan-25 aryan-25 commented Jun 28, 2024

Motivation:

  • When the leading slash is omitted in the string argument of a relative URL instance constructed from init(string:relativeTo), requests made with this URL instance fail. This is because the underlying HTTP parser fails when there is no leading slash in the URI.

Modifications:

  • The URI of a URL instance is obtained from a computed property uri in HTTPHandler.swift, which in turn calls the percentEncodedPath computed property.
    • The percentEncodedPath property uses URLComponents to extract out the path.
    • The resolvingAgainstBaseURL argument to the URLComponents constructor was modified from false to true

Result:

  • Regardless of whether a user provides or omits a leading slash in the path of a relative URL, the uri property will always contain a leading slash.

@aryan-25 aryan-25 closed this Jul 3, 2024
@aryan-25 aryan-25 reopened this Jul 3, 2024
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.

Looks great. Please compare against static absolute values in tests.

Tests/AsyncHTTPClientTests/HTTPClientInternalTests.swift Outdated Show resolved Hide resolved
Tests/AsyncHTTPClientTests/HTTPClientTests.swift Outdated Show resolved Hide resolved
@fabianfett fabianfett added the semver/patch For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) label Jul 8, 2024
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.

LGTM! Thank you!

@fabianfett fabianfett merged commit 54d1006 into swift-server:main Jul 9, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants