From 9e82eeb498e3e56067cd362d778c4c704b3f50dd Mon Sep 17 00:00:00 2001 From: Ludovic Dewailly Date: Wed, 21 Aug 2019 10:26:53 +0100 Subject: [PATCH] redirects ignore EventLoop preference - issue#88 --- Sources/AsyncHTTPClient/HTTPClient.swift | 2 +- Tests/AsyncHTTPClientTests/HTTPClientTests.swift | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Sources/AsyncHTTPClient/HTTPClient.swift b/Sources/AsyncHTTPClient/HTTPClient.swift index 949b09e70..55db26ce2 100644 --- a/Sources/AsyncHTTPClient/HTTPClient.swift +++ b/Sources/AsyncHTTPClient/HTTPClient.swift @@ -215,7 +215,7 @@ public class HTTPClient { let redirectHandler: RedirectHandler? if self.configuration.followRedirects { redirectHandler = RedirectHandler(request: request) { newRequest in - self.execute(request: newRequest, delegate: delegate, deadline: deadline) + self.execute(request: newRequest, delegate: delegate, eventLoop: eventLoop, deadline: deadline) } } else { redirectHandler = nil diff --git a/Tests/AsyncHTTPClientTests/HTTPClientTests.swift b/Tests/AsyncHTTPClientTests/HTTPClientTests.swift index c9b85e957..70a776c4d 100644 --- a/Tests/AsyncHTTPClientTests/HTTPClientTests.swift +++ b/Tests/AsyncHTTPClientTests/HTTPClientTests.swift @@ -487,8 +487,9 @@ class HTTPClientTests: XCTestCase { func testEventLoopArgument() throws { let httpBin = HttpBin() - let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) - let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup)) + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 5) + let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup), + configuration: HTTPClient.Configuration(followRedirects: true)) defer { try! eventLoopGroup.syncShutdownGracefully() httpBin.shutdown() @@ -516,9 +517,13 @@ class HTTPClientTests: XCTestCase { let eventLoop = eventLoopGroup.next() let delegate = EventLoopValidatingDelegate(eventLoop: eventLoop) - let request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/get") - let response = try httpClient.execute(request: request, delegate: delegate, eventLoop: .prefers(eventLoop)).wait() + var request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/get") + var response = try httpClient.execute(request: request, delegate: delegate, eventLoop: .prefers(eventLoop)).wait() + XCTAssertEqual(true, response) + // redirect + request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/redirect/302") + response = try httpClient.execute(request: request, delegate: delegate, eventLoop: .prefers(eventLoop)).wait() XCTAssertEqual(true, response) } }