Skip to content

Commit f26c6d2

Browse files
authored
Merge branch 'main' into mptcp-support
2 parents 6190e9e + 6df8e1c commit f26c6d2

File tree

7 files changed

+65
-6
lines changed

7 files changed

+65
-6
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.library(name: "AsyncHTTPClient", targets: ["AsyncHTTPClient"]),
2222
],
2323
dependencies: [
24-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.62.0"),
24+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.71.0"),
2525
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.27.1"),
2626
.package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.19.0"),
2727
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.13.0"),

Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ extension HTTPClientResponse {
108108
case .transaction(_, let expectedContentLength):
109109
if let contentLength = expectedContentLength {
110110
if contentLength > maxBytes {
111-
throw NIOTooManyBytesError()
111+
throw NIOTooManyBytesError(maxBytes: maxBytes)
112112
}
113113
}
114114
case .anyAsyncSequence:

Sources/AsyncHTTPClient/ConnectionPool/HTTP1/HTTP1ClientChannelHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,8 @@ struct IdleWriteStateMachine {
665665
self.state = .requestEndSent
666666
return .clearIdleWriteTimeoutTimer
667667
case .waitingForWritabilityEnabled:
668-
preconditionFailure("If the channel is not writable, we can't have sent the request end.")
668+
self.state = .requestEndSent
669+
return .none
669670
case .requestEndSent:
670671
return .none
671672
}

Sources/AsyncHTTPClient/HTTPClient+HTTPCookie.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import NIOHTTP1
16-
#if canImport(Darwin)
16+
#if canImport(xlocale)
17+
import xlocale
18+
#elseif canImport(locale_h)
19+
import locale_h
20+
#elseif canImport(Darwin)
1721
import Darwin
1822
#elseif canImport(Musl)
1923
import Musl

Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
907907
await XCTAssertThrowsError(
908908
try await response.body.collect(upTo: 3)
909909
) {
910-
XCTAssertEqualTypeAndValue($0, NIOTooManyBytesError())
910+
XCTAssertEqualTypeAndValue($0, NIOTooManyBytesError(maxBytes: 3))
911911
}
912912
}
913913
}

Tests/AsyncHTTPClientTests/HTTP1ClientChannelHandlerTests.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,56 @@ class HTTP1ClientChannelHandlerTests: XCTestCase {
376376
}
377377
}
378378

379+
func testIdleWriteTimeoutRaceToEnd() {
380+
let embedded = EmbeddedChannel()
381+
var maybeTestUtils: HTTP1TestTools?
382+
XCTAssertNoThrow(maybeTestUtils = try embedded.setupHTTP1Connection())
383+
guard let testUtils = maybeTestUtils else { return XCTFail("Expected connection setup works") }
384+
385+
var maybeRequest: HTTPClient.Request?
386+
XCTAssertNoThrow(maybeRequest = try HTTPClient.Request(url: "http://localhost/", method: .POST, body: .stream { _ in
387+
// Advance time by more than the idle write timeout (that's 1 millisecond) to trigger the timeout.
388+
let scheduled = embedded.embeddedEventLoop.flatScheduleTask(in: .milliseconds(2)) {
389+
embedded.embeddedEventLoop.makeSucceededVoidFuture()
390+
}
391+
return scheduled.futureResult
392+
}))
393+
394+
guard let request = maybeRequest else { return XCTFail("Expected to be able to create a request") }
395+
396+
let delegate = ResponseAccumulator(request: request)
397+
var maybeRequestBag: RequestBag<ResponseAccumulator>?
398+
XCTAssertNoThrow(maybeRequestBag = try RequestBag(
399+
request: request,
400+
eventLoopPreference: .delegate(on: embedded.eventLoop),
401+
task: .init(eventLoop: embedded.eventLoop, logger: testUtils.logger),
402+
redirectHandler: nil,
403+
connectionDeadline: .now() + .seconds(30),
404+
requestOptions: .forTests(idleWriteTimeout: .milliseconds(5)),
405+
delegate: delegate
406+
))
407+
guard let requestBag = maybeRequestBag else { return XCTFail("Expected to be able to create a request bag") }
408+
409+
embedded.isWritable = true
410+
embedded.pipeline.fireChannelWritabilityChanged()
411+
testUtils.connection.executeRequest(requestBag)
412+
let expectedHeaders: HTTPHeaders = ["host": "localhost", "Transfer-Encoding": "chunked"]
413+
XCTAssertEqual(
414+
try embedded.readOutbound(as: HTTPClientRequestPart.self),
415+
.head(HTTPRequestHead(version: .http1_1, method: .POST, uri: "/", headers: expectedHeaders))
416+
)
417+
418+
// change the writability to false.
419+
embedded.isWritable = false
420+
embedded.pipeline.fireChannelWritabilityChanged()
421+
embedded.embeddedEventLoop.run()
422+
423+
// let the writer, write an end (while writability is false)
424+
embedded.embeddedEventLoop.advanceTime(by: .milliseconds(2))
425+
426+
XCTAssertEqual(try embedded.readOutbound(as: HTTPClientRequestPart.self), .end(nil))
427+
}
428+
379429
func testIdleWriteTimeoutWritabilityChanged() {
380430
let embedded = EmbeddedChannel()
381431
let testWriter = TestBackpressureWriter(eventLoop: embedded.eventLoop, parts: 5)

Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ import NIOSSL
2828
import NIOTLS
2929
import NIOTransportServices
3030
import XCTest
31-
#if canImport(Darwin)
31+
#if canImport(xlocale)
32+
import xlocale
33+
#elseif canImport(locale_h)
34+
import locale_h
35+
#elseif canImport(Darwin)
3236
import Darwin
3337
#elseif canImport(Musl)
3438
import Musl

0 commit comments

Comments
 (0)