File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Tests/AsyncHTTPClientTests Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -362,7 +362,7 @@ final class RequestBag<Delegate: HTTPClientResponseDelegate> {
362
362
363
363
self . executeFailAction0 ( action)
364
364
365
- self . redirectTask? . cancel ( )
365
+ self . redirectTask? . fail ( reason : error )
366
366
}
367
367
368
368
private func executeFailAction0( _ action: RequestBag < Delegate > . StateMachine . FailAction ) {
Original file line number Diff line number Diff line change @@ -4159,6 +4159,35 @@ final class HTTPClientTests: XCTestCaseHTTPClientTestsBaseClass {
4159
4159
}
4160
4160
}
4161
4161
4162
+ func testFailingRequestAfterRedirect( ) throws {
4163
+ let request = try Request (
4164
+ url: self . defaultHTTPBinURLPrefix + " redirect/target " ,
4165
+ method: . GET,
4166
+ headers: [ " X-Target-Redirect-URL " : self . defaultHTTPBinURLPrefix + " wait " ] ,
4167
+ body: nil
4168
+ )
4169
+
4170
+ class FailAfterRedirect : HTTPClientResponseDelegate {
4171
+ init ( ) { }
4172
+ func didFinishRequest( task: AsyncHTTPClient . HTTPClient . Task < Void > ) throws { }
4173
+ }
4174
+
4175
+ let task = defaultClient. execute ( request: request, delegate: FailAfterRedirect ( ) , deadline: . now( ) + . seconds( 1 ) )
4176
+
4177
+ // there is currently no HTTPClientResponseDelegate method to ensure the redirect occurs before we fail, so we just sleep for 500ms
4178
+ Thread . sleep ( forTimeInterval: 0.5 )
4179
+
4180
+ struct TestError : Error { }
4181
+
4182
+ task. fail ( reason: TestError ( ) )
4183
+
4184
+ XCTAssertThrowsError ( try task. wait ( ) ) { error in
4185
+ guard error is TestError else {
4186
+ return XCTFail ( " Should fail with TestError " )
4187
+ }
4188
+ }
4189
+ }
4190
+
4162
4191
func testCancelingHTTP1RequestAfterHeaderSend( ) throws {
4163
4192
var request = try HTTPClient . Request ( url: self . defaultHTTPBin. baseURL + " /wait " , method: . POST)
4164
4193
// non-empty body is important
You can’t perform that action at this time.
0 commit comments