Skip to content

Commit e2f66e8

Browse files
committed
(134382481) URLComponents: support http(s)+unix schemes
1 parent 2966e02 commit e2f66e8

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
@@ -1103,4 +1103,38 @@ final class URLTests : XCTestCase {
11031103
XCTAssertEqual(urlComponents.string, nsURLComponents.string)
11041104
}
11051105
#endif
1106+
1107+
func testURLComponentsUnixDomainSocketOverHTTPScheme() {
1108+
var comp = URLComponents()
1109+
comp.scheme = "http+unix"
1110+
comp.host = "/path/to/socket"
1111+
comp.path = "/info"
1112+
XCTAssertEqual(comp.string, "http+unix://%2Fpath%2Fto%2Fsocket/info")
1113+
1114+
comp.scheme = "https+unix"
1115+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1116+
1117+
comp.encodedHost = "%2Fpath%2Fto%2Fsocket"
1118+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1119+
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
1120+
XCTAssertEqual(comp.host, "/path/to/socket")
1121+
XCTAssertEqual(comp.path, "/info")
1122+
1123+
// "/path/to/socket" is not a valid host for schemes
1124+
// that IDNA-encode hosts instead of percent-encoding
1125+
comp.scheme = "http"
1126+
XCTAssertNil(comp.string)
1127+
1128+
comp.scheme = "https"
1129+
XCTAssertNil(comp.string)
1130+
1131+
comp.scheme = "https+unix"
1132+
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
1133+
1134+
// Check that we can parse a percent-encoded http+unix URL string
1135+
comp = URLComponents(string: "http+unix://%2Fpath%2Fto%2Fsocket/info")!
1136+
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
1137+
XCTAssertEqual(comp.host, "/path/to/socket")
1138+
XCTAssertEqual(comp.path, "/info")
1139+
}
11061140
}

0 commit comments

Comments
 (0)