Skip to content

[6.0] URLComponents: support http(s)+unix schemes #903

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 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/URL/URLParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ internal struct RFC3986Parser: URLParserProtocol {
"addressbook",
"contact",
"phasset",
"http+unix",
"https+unix",
])

private static func looksLikeIPLiteral(_ host: some StringProtocol) -> Bool {
Expand Down
34 changes: 34 additions & 0 deletions Tests/FoundationEssentialsTests/URLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1031,4 +1031,38 @@ final class URLTests : XCTestCase {
XCTAssertEqual(comp.percentEncodedPath, "/my%00path")
XCTAssertEqual(comp.path, "/my\u{0}path")
}

func testURLComponentsUnixDomainSocketOverHTTPScheme() {
var comp = URLComponents()
comp.scheme = "http+unix"
comp.host = "/path/to/socket"
comp.path = "/info"
XCTAssertEqual(comp.string, "http+unix://%2Fpath%2Fto%2Fsocket/info")

comp.scheme = "https+unix"
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")

comp.encodedHost = "%2Fpath%2Fto%2Fsocket"
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
XCTAssertEqual(comp.host, "/path/to/socket")
XCTAssertEqual(comp.path, "/info")

// "/path/to/socket" is not a valid host for schemes
// that IDNA-encode hosts instead of percent-encoding
comp.scheme = "http"
XCTAssertNil(comp.string)

comp.scheme = "https"
XCTAssertNil(comp.string)

comp.scheme = "https+unix"
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")

// Check that we can parse a percent-encoded http+unix URL string
comp = URLComponents(string: "http+unix://%2Fpath%2Fto%2Fsocket/info")!
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
XCTAssertEqual(comp.host, "/path/to/socket")
XCTAssertEqual(comp.path, "/info")
}
}