Skip to content

Commit e828556

Browse files
authored
(134382481) URLComponents: support http(s)+unix schemes (#903) (#913)
1 parent 56c44b0 commit e828556

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Sources/FoundationEssentials/URL/URLParser.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ internal struct RFC3986Parser: URLParserProtocol {
222222
"addressbook",
223223
"contact",
224224
"phasset",
225+
"http+unix",
226+
"https+unix",
225227
])
226228

227229
private static func looksLikeIPLiteral(_ host: some StringProtocol) -> Bool {

Tests/FoundationEssentialsTests/URLTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,4 +1031,38 @@ final class URLTests : XCTestCase {
10311031
XCTAssertEqual(comp.percentEncodedPath, "/my%00path")
10321032
XCTAssertEqual(comp.path, "/my\u{0}path")
10331033
}
1034+
1035+
func testURLComponentsUnixDomainSocketOverHTTPScheme() {
1036+
var comp = URLComponents()
1037+
comp.scheme = "http+unix"
1038+
comp.host = "/path/to/socket"
1039+
comp.path = "/info"
1040+
XCTAssertEqual(comp.string, "http+unix://%2Fpath%2Fto%2Fsocket/info")
1041+
1042+
comp.scheme = "https+unix"
1043+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1044+
1045+
comp.encodedHost = "%2Fpath%2Fto%2Fsocket"
1046+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1047+
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
1048+
XCTAssertEqual(comp.host, "/path/to/socket")
1049+
XCTAssertEqual(comp.path, "/info")
1050+
1051+
// "/path/to/socket" is not a valid host for schemes
1052+
// that IDNA-encode hosts instead of percent-encoding
1053+
comp.scheme = "http"
1054+
XCTAssertNil(comp.string)
1055+
1056+
comp.scheme = "https"
1057+
XCTAssertNil(comp.string)
1058+
1059+
comp.scheme = "https+unix"
1060+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1061+
1062+
// Check that we can parse a percent-encoded http+unix URL string
1063+
comp = URLComponents(string: "http+unix://%2Fpath%2Fto%2Fsocket/info")!
1064+
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
1065+
XCTAssertEqual(comp.host, "/path/to/socket")
1066+
XCTAssertEqual(comp.path, "/info")
1067+
}
10341068
}

0 commit comments

Comments
 (0)