Skip to content

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.

@fabianfett fabianfett added the 🔨 semver/patch No public API change. 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
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.

2 participants