async-http-client icon indicating copy to clipboard operation
async-http-client copied to clipboard

Fix leading slash issue in relative URL requests

Open aryan-25 opened this issue 1 year ago • 0 comments

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 avatar Jun 28 '24 08:06 aryan-25