@@ -67,6 +67,37 @@ class HTTPClientInternalTests: XCTestCase {
67
67
XCTAssertNoThrow ( try channel. writeInbound ( HTTPClientResponsePart . end ( nil ) ) )
68
68
}
69
69
70
+ func testHostPort( ) throws {
71
+ let channel = EmbeddedChannel ( )
72
+ let recorder = RecordingHandler < HTTPClientResponsePart , HTTPClientRequestPart > ( )
73
+ let task = Task < Void > ( eventLoop: channel. eventLoop, logger: HTTPClient . loggingDisabled)
74
+
75
+ try channel. pipeline. addHandler ( recorder) . wait ( )
76
+ try channel. pipeline. addHandler ( TaskHandler ( task: task,
77
+ kind: . host,
78
+ delegate: TestHTTPDelegate ( ) ,
79
+ redirectHandler: nil ,
80
+ ignoreUncleanSSLShutdown: false ,
81
+ logger: HTTPClient . loggingDisabled) ) . wait ( )
82
+
83
+ let request1 = try Request ( url: " http://localhost:80/get " )
84
+ XCTAssertNoThrow ( try channel. writeOutbound ( request1) )
85
+ let request2 = try Request ( url: " https://localhost/get " )
86
+ XCTAssertNoThrow ( try channel. writeOutbound ( request2) )
87
+ let request3 = try Request ( url: " http://localhost:8080/get " )
88
+ XCTAssertNoThrow ( try channel. writeOutbound ( request3) )
89
+
90
+ var head1 = HTTPRequestHead ( version: HTTPVersion ( major: 1 , minor: 1 ) , method: . GET, uri: " /get " )
91
+ head1. headers. add ( name: " Host " , value: " localhost " )
92
+ XCTAssertEqual ( HTTPClientRequestPart . head ( head1) , recorder. writes [ 0 ] )
93
+ var head2 = HTTPRequestHead ( version: HTTPVersion ( major: 1 , minor: 1 ) , method: . GET, uri: " /get " )
94
+ head2. headers. add ( name: " Host " , value: " localhost " )
95
+ XCTAssertEqual ( HTTPClientRequestPart . head ( head2) , recorder. writes [ 2 ] )
96
+ var head3 = HTTPRequestHead ( version: HTTPVersion ( major: 1 , minor: 1 ) , method: . GET, uri: " /get " )
97
+ head3. headers. add ( name: " Host " , value: " localhost:8080 " )
98
+ XCTAssertEqual ( HTTPClientRequestPart . head ( head3) , recorder. writes [ 4 ] )
99
+ }
100
+
70
101
func testBadHTTPRequest( ) throws {
71
102
let channel = EmbeddedChannel ( )
72
103
let recorder = RecordingHandler < HTTPClientResponsePart , HTTPClientRequestPart > ( )
@@ -90,6 +121,37 @@ class HTTPClientInternalTests: XCTestCase {
90
121
}
91
122
}
92
123
124
+ func testHostPort( ) throws {
125
+ let channel = EmbeddedChannel ( )
126
+ let recorder = RecordingHandler < HTTPClientResponsePart , HTTPClientRequestPart > ( )
127
+ let task = Task < Void > ( eventLoop: channel. eventLoop, logger: HTTPClient . loggingDisabled)
128
+
129
+ try channel. pipeline. addHandler ( recorder) . wait ( )
130
+ try channel. pipeline. addHandler ( TaskHandler ( task: task,
131
+ kind: . host,
132
+ delegate: TestHTTPDelegate ( ) ,
133
+ redirectHandler: nil ,
134
+ ignoreUncleanSSLShutdown: false ,
135
+ logger: HTTPClient . loggingDisabled) ) . wait ( )
136
+
137
+ let request1 = try Request ( url: " http://localhost:80/get " )
138
+ XCTAssertNoThrow ( try channel. writeOutbound ( request1) )
139
+ let request2 = try Request ( url: " https://localhost/get " )
140
+ XCTAssertNoThrow ( try channel. writeOutbound ( request2) )
141
+ let request3 = try Request ( url: " http://localhost:8080/get " )
142
+ XCTAssertNoThrow ( try channel. writeOutbound ( request3) )
143
+
144
+ var head1 = HTTPRequestHead ( version: HTTPVersion ( major: 1 , minor: 1 ) , method: . GET, uri: " /get " )
145
+ head1. headers. add ( name: " Host " , value: " localhost " )
146
+ XCTAssertEqual ( HTTPClientRequestPart . head ( head1) , recorder. writes [ 0 ] )
147
+ var head2 = HTTPRequestHead ( version: HTTPVersion ( major: 1 , minor: 1 ) , method: . GET, uri: " /get " )
148
+ head2. headers. add ( name: " Host " , value: " localhost " )
149
+ XCTAssertEqual ( HTTPClientRequestPart . head ( head2) , recorder. writes [ 2 ] )
150
+ var head3 = HTTPRequestHead ( version: HTTPVersion ( major: 1 , minor: 1 ) , method: . GET, uri: " /get " )
151
+ head3. headers. add ( name: " Host " , value: " localhost:8080 " )
152
+ XCTAssertEqual ( HTTPClientRequestPart . head ( head3) , recorder. writes [ 4 ] )
153
+ }
154
+
93
155
func testHTTPPartsHandlerMultiBody( ) throws {
94
156
let channel = EmbeddedChannel ( )
95
157
let delegate = TestHTTPDelegate ( )
0 commit comments