Skip to content

Commit 9e82eeb

Browse files
author
Ludovic Dewailly
committed
redirects ignore EventLoop preference - issue#88
1 parent 64851a1 commit 9e82eeb

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Sources/AsyncHTTPClient/HTTPClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public class HTTPClient {
215215
let redirectHandler: RedirectHandler<T.Response>?
216216
if self.configuration.followRedirects {
217217
redirectHandler = RedirectHandler<T.Response>(request: request) { newRequest in
218-
self.execute(request: newRequest, delegate: delegate, deadline: deadline)
218+
self.execute(request: newRequest, delegate: delegate, eventLoop: eventLoop, deadline: deadline)
219219
}
220220
} else {
221221
redirectHandler = nil

Tests/AsyncHTTPClientTests/HTTPClientTests.swift

+9-4
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,9 @@ class HTTPClientTests: XCTestCase {
487487

488488
func testEventLoopArgument() throws {
489489
let httpBin = HttpBin()
490-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
491-
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))
490+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 5)
491+
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup),
492+
configuration: HTTPClient.Configuration(followRedirects: true))
492493
defer {
493494
try! eventLoopGroup.syncShutdownGracefully()
494495
httpBin.shutdown()
@@ -516,9 +517,13 @@ class HTTPClientTests: XCTestCase {
516517

517518
let eventLoop = eventLoopGroup.next()
518519
let delegate = EventLoopValidatingDelegate(eventLoop: eventLoop)
519-
let request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/get")
520-
let response = try httpClient.execute(request: request, delegate: delegate, eventLoop: .prefers(eventLoop)).wait()
520+
var request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/get")
521+
var response = try httpClient.execute(request: request, delegate: delegate, eventLoop: .prefers(eventLoop)).wait()
522+
XCTAssertEqual(true, response)
521523

524+
// redirect
525+
request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/redirect/302")
526+
response = try httpClient.execute(request: request, delegate: delegate, eventLoop: .prefers(eventLoop)).wait()
522527
XCTAssertEqual(true, response)
523528
}
524529
}

0 commit comments

Comments
 (0)