Skip to content

Commit 307a45d

Browse files
committed
(134382481) URLComponents: support http(s)+unix schemes
1 parent e34e1c9 commit 307a45d

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
@@ -1082,4 +1082,38 @@ final class URLTests : XCTestCase {
10821082
XCTAssertEqual(comp.percentEncodedPath, "/my%00path")
10831083
XCTAssertEqual(comp.path, "/my\u{0}path")
10841084
}
1085+
1086+
func testURLComponentsUnixDomainSocketOverHTTPScheme() {
1087+
var comp = URLComponents()
1088+
comp.scheme = "http+unix"
1089+
comp.host = "/path/to/socket"
1090+
comp.path = "/info"
1091+
XCTAssertEqual(comp.string, "http+unix://%2Fpath%2Fto%2Fsocket/info")
1092+
1093+
comp.scheme = "https+unix"
1094+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1095+
1096+
comp.encodedHost = "%2Fpath%2Fto%2Fsocket"
1097+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1098+
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
1099+
XCTAssertEqual(comp.host, "/path/to/socket")
1100+
XCTAssertEqual(comp.path, "/info")
1101+
1102+
// "/path/to/socket" is not a valid host for schemes
1103+
// that IDNA-encode hosts instead of percent-encoding
1104+
comp.scheme = "http"
1105+
XCTAssertNil(comp.string)
1106+
1107+
comp.scheme = "https"
1108+
XCTAssertNil(comp.string)
1109+
1110+
comp.scheme = "https+unix"
1111+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1112+
1113+
// Check that we can parse a percent-encoded http+unix URL string
1114+
comp = URLComponents(string: "http+unix://%2Fpath%2Fto%2Fsocket/info")!
1115+
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
1116+
XCTAssertEqual(comp.host, "/path/to/socket")
1117+
XCTAssertEqual(comp.path, "/info")
1118+
}
10851119
}

0 commit comments

Comments
 (0)