Skip to content

Commit

Permalink
Add Host header (swift-server#650) (swift-server#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaelIsaev authored Dec 6, 2022
1 parent 2859c10 commit 49abfc3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ final class HTTP1ProxyConnectHandler: ChannelDuplexHandler, RemovableChannelHand
method: .CONNECT,
uri: "\(self.targetHost):\(self.targetPort)"
)
head.headers.replaceOrAdd(name: "host", value: "\(self.targetHost)")
if let authorization = self.proxyAuthorization {
head.headers.replaceOrAdd(name: "proxy-authorization", value: authorization.headerValue)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class HTTP1ProxyConnectHandlerTests: XCTestCase {

XCTAssertEqual(head.method, .CONNECT)
XCTAssertEqual(head.uri, "swift.org:443")
XCTAssertEqual(head.headers["host"].first, "swift.org")
XCTAssertNil(head.headers["proxy-authorization"].first)
XCTAssertEqual(try embedded.readOutbound(as: HTTPClientRequestPart.self), .end(nil))

Expand Down Expand Up @@ -76,6 +77,7 @@ class HTTP1ProxyConnectHandlerTests: XCTestCase {

XCTAssertEqual(head.method, .CONNECT)
XCTAssertEqual(head.uri, "swift.org:443")
XCTAssertEqual(head.headers["host"].first, "swift.org")
XCTAssertEqual(head.headers["proxy-authorization"].first, "Basic abc123")
XCTAssertEqual(try embedded.readOutbound(as: HTTPClientRequestPart.self), .end(nil))

Expand Down Expand Up @@ -109,6 +111,7 @@ class HTTP1ProxyConnectHandlerTests: XCTestCase {

XCTAssertEqual(head.method, .CONNECT)
XCTAssertEqual(head.uri, "swift.org:443")
XCTAssertEqual(head.headers["host"].first, "swift.org")
XCTAssertNil(head.headers["proxy-authorization"].first)
XCTAssertEqual(try embedded.readOutbound(as: HTTPClientRequestPart.self), .end(nil))

Expand Down Expand Up @@ -148,6 +151,7 @@ class HTTP1ProxyConnectHandlerTests: XCTestCase {

XCTAssertEqual(head.method, .CONNECT)
XCTAssertEqual(head.uri, "swift.org:443")
XCTAssertEqual(head.headers["host"].first, "swift.org")
XCTAssertNil(head.headers["proxy-authorization"].first)
XCTAssertEqual(try embedded.readOutbound(as: HTTPClientRequestPart.self), .end(nil))

Expand Down Expand Up @@ -187,6 +191,7 @@ class HTTP1ProxyConnectHandlerTests: XCTestCase {

XCTAssertEqual(head.method, .CONNECT)
XCTAssertEqual(head.uri, "swift.org:443")
XCTAssertEqual(head.headers["host"].first, "swift.org")
XCTAssertEqual(try embedded.readOutbound(as: HTTPClientRequestPart.self), .end(nil))

let responseHead = HTTPResponseHead(version: .http1_1, status: .ok)
Expand Down

0 comments on commit 49abfc3

Please sign in to comment.