Skip to content

Commit 3c2c36a

Browse files
authored
(134382481) URLComponents: support http(s)+unix schemes (#903)
1 parent d7ce7ef commit 3c2c36a

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
@@ -1036,4 +1036,38 @@ final class URLTests : XCTestCase {
10361036
XCTAssertEqual(comp.percentEncodedPath, "/my%00path")
10371037
XCTAssertEqual(comp.path, "/my\u{0}path")
10381038
}
1039+
1040+
func testURLComponentsUnixDomainSocketOverHTTPScheme() {
1041+
var comp = URLComponents()
1042+
comp.scheme = "http+unix"
1043+
comp.host = "/path/to/socket"
1044+
comp.path = "/info"
1045+
XCTAssertEqual(comp.string, "http+unix://%2Fpath%2Fto%2Fsocket/info")
1046+
1047+
comp.scheme = "https+unix"
1048+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1049+
1050+
comp.encodedHost = "%2Fpath%2Fto%2Fsocket"
1051+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1052+
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
1053+
XCTAssertEqual(comp.host, "/path/to/socket")
1054+
XCTAssertEqual(comp.path, "/info")
1055+
1056+
// "/path/to/socket" is not a valid host for schemes
1057+
// that IDNA-encode hosts instead of percent-encoding
1058+
comp.scheme = "http"
1059+
XCTAssertNil(comp.string)
1060+
1061+
comp.scheme = "https"
1062+
XCTAssertNil(comp.string)
1063+
1064+
comp.scheme = "https+unix"
1065+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1066+
1067+
// Check that we can parse a percent-encoded http+unix URL string
1068+
comp = URLComponents(string: "http+unix://%2Fpath%2Fto%2Fsocket/info")!
1069+
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
1070+
XCTAssertEqual(comp.host, "/path/to/socket")
1071+
XCTAssertEqual(comp.path, "/info")
1072+
}
10391073
}

0 commit comments

Comments
 (0)