Skip to content

Commit 1f3f141

Browse files
authored
Remove redundant RequestFramingMetadata.Body.none case (#480)
1 parent ec2e080 commit 1f3f141

6 files changed

+47
-47
lines changed

Sources/AsyncHTTPClient/ConnectionPool/HTTPRequestStateMachine.swift

+6-5
Original file line numberDiff line numberDiff line change
@@ -665,13 +665,14 @@ struct HTTPRequestStateMachine {
665665
case .stream:
666666
self.state = .running(.streaming(expectedBodyLength: nil, sentBodyBytes: 0, producer: .producing), .waitingForHead)
667667
return .sendRequestHead(head, startBody: true)
668-
case .fixedSize(let length) where length > 0:
669-
self.state = .running(.streaming(expectedBodyLength: length, sentBodyBytes: 0, producer: .producing), .waitingForHead)
670-
return .sendRequestHead(head, startBody: true)
671-
case .none, .fixedSize:
672-
// fallback if fixed size is 0
668+
case .fixedSize(0):
669+
// no body
673670
self.state = .running(.endSent, .waitingForHead)
674671
return .sendRequestHead(head, startBody: false)
672+
case .fixedSize(let length):
673+
// length is greater than zero and we therefore have a body to send
674+
self.state = .running(.streaming(expectedBodyLength: length, sentBodyBytes: 0, producer: .producing), .waitingForHead)
675+
return .sendRequestHead(head, startBody: true)
675676
}
676677
}
677678
}

Sources/AsyncHTTPClient/ConnectionPool/RequestFramingMetadata.swift

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
struct RequestFramingMetadata: Hashable {
1616
enum Body: Hashable {
17-
case none
1817
case stream
1918
case fixedSize(Int)
2019
}

Sources/AsyncHTTPClient/RequestValidation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import NIOHTTP1
1717

1818
extension HTTPHeaders {
1919
mutating func validate(method: HTTPMethod, body: HTTPClient.Body?) throws -> RequestFramingMetadata {
20-
var metadata = RequestFramingMetadata(connectionClose: false, body: .none)
20+
var metadata = RequestFramingMetadata(connectionClose: false, body: .fixedSize(0))
2121

2222
if self[canonicalForm: "connection"].lazy.map({ $0.lowercased() }).contains("close") {
2323
metadata.connectionClose = true

Tests/AsyncHTTPClientTests/HTTP1ConnectionStateMachineTests.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class HTTP1ConnectionStateMachineTests: XCTestCase {
6262
XCTAssertEqual(state.channelActive(isWritable: true), .fireChannelActive)
6363

6464
let requestHead = HTTPRequestHead(version: .http1_1, method: .GET, uri: "/")
65-
let metadata = RequestFramingMetadata(connectionClose: false, body: .none)
65+
let metadata = RequestFramingMetadata(connectionClose: false, body: .fixedSize(0))
6666
let newRequestAction = state.runNewRequest(head: requestHead, metadata: metadata)
6767
XCTAssertEqual(newRequestAction, .sendRequestHead(requestHead, startBody: false))
6868

@@ -90,7 +90,7 @@ class HTTP1ConnectionStateMachineTests: XCTestCase {
9090
var state = HTTP1ConnectionStateMachine()
9191
XCTAssertEqual(state.channelActive(isWritable: true), .fireChannelActive)
9292
let requestHead = HTTPRequestHead(version: .http1_1, method: .GET, uri: "/", headers: ["connection": "close"])
93-
let metadata = RequestFramingMetadata(connectionClose: true, body: .none)
93+
let metadata = RequestFramingMetadata(connectionClose: true, body: .fixedSize(0))
9494
let newRequestAction = state.runNewRequest(head: requestHead, metadata: metadata)
9595
XCTAssertEqual(newRequestAction, .sendRequestHead(requestHead, startBody: false))
9696

@@ -106,7 +106,7 @@ class HTTP1ConnectionStateMachineTests: XCTestCase {
106106
var state = HTTP1ConnectionStateMachine()
107107
XCTAssertEqual(state.channelActive(isWritable: true), .fireChannelActive)
108108
let requestHead = HTTPRequestHead(version: .http1_1, method: .GET, uri: "/")
109-
let metadata = RequestFramingMetadata(connectionClose: false, body: .none)
109+
let metadata = RequestFramingMetadata(connectionClose: false, body: .fixedSize(0))
110110
let newRequestAction = state.runNewRequest(head: requestHead, metadata: metadata)
111111
XCTAssertEqual(newRequestAction, .sendRequestHead(requestHead, startBody: false))
112112

@@ -122,7 +122,7 @@ class HTTP1ConnectionStateMachineTests: XCTestCase {
122122
var state = HTTP1ConnectionStateMachine()
123123
XCTAssertEqual(state.channelActive(isWritable: true), .fireChannelActive)
124124
let requestHead = HTTPRequestHead(version: .http1_1, method: .GET, uri: "/")
125-
let metadata = RequestFramingMetadata(connectionClose: false, body: .none)
125+
let metadata = RequestFramingMetadata(connectionClose: false, body: .fixedSize(0))
126126
let newRequestAction = state.runNewRequest(head: requestHead, metadata: metadata)
127127
XCTAssertEqual(newRequestAction, .sendRequestHead(requestHead, startBody: false))
128128

@@ -139,7 +139,7 @@ class HTTP1ConnectionStateMachineTests: XCTestCase {
139139
XCTAssertEqual(state.channelActive(isWritable: false), .fireChannelActive)
140140
XCTAssertEqual(state.writabilityChanged(writable: true), .wait)
141141
let requestHead = HTTPRequestHead(version: .http1_1, method: .GET, uri: "/")
142-
let metadata = RequestFramingMetadata(connectionClose: false, body: .none)
142+
let metadata = RequestFramingMetadata(connectionClose: false, body: .fixedSize(0))
143143
let newRequestAction = state.runNewRequest(head: requestHead, metadata: metadata)
144144
XCTAssertEqual(newRequestAction, .sendRequestHead(requestHead, startBody: false))
145145

@@ -168,7 +168,7 @@ class HTTP1ConnectionStateMachineTests: XCTestCase {
168168
XCTAssertEqual(state.channelActive(isWritable: true), .fireChannelActive)
169169

170170
let requestHead = HTTPRequestHead(version: .http1_1, method: .GET, uri: "/")
171-
let metadata = RequestFramingMetadata(connectionClose: false, body: .none)
171+
let metadata = RequestFramingMetadata(connectionClose: false, body: .fixedSize(0))
172172
let newRequestAction = state.runNewRequest(head: requestHead, metadata: metadata)
173173
XCTAssertEqual(newRequestAction, .sendRequestHead(requestHead, startBody: false))
174174

@@ -233,7 +233,7 @@ class HTTP1ConnectionStateMachineTests: XCTestCase {
233233
var state = HTTP1ConnectionStateMachine()
234234
XCTAssertEqual(state.channelActive(isWritable: true), .fireChannelActive)
235235
let requestHead = HTTPRequestHead(version: .http1_1, method: .GET, uri: "/")
236-
let metadata = RequestFramingMetadata(connectionClose: false, body: .none)
236+
let metadata = RequestFramingMetadata(connectionClose: false, body: .fixedSize(0))
237237
let newRequestAction = state.runNewRequest(head: requestHead, metadata: metadata)
238238
XCTAssertEqual(newRequestAction, .sendRequestHead(requestHead, startBody: false))
239239
let responseHead = HTTPResponseHead(version: .http1_1, status: .ok)
@@ -248,7 +248,7 @@ class HTTP1ConnectionStateMachineTests: XCTestCase {
248248
var state = HTTP1ConnectionStateMachine()
249249
XCTAssertEqual(state.channelActive(isWritable: true), .fireChannelActive)
250250
let requestHead = HTTPRequestHead(version: .http1_1, method: .GET, uri: "/")
251-
let metadata = RequestFramingMetadata(connectionClose: false, body: .none)
251+
let metadata = RequestFramingMetadata(connectionClose: false, body: .fixedSize(0))
252252
let newRequestAction = state.runNewRequest(head: requestHead, metadata: metadata)
253253
XCTAssertEqual(newRequestAction, .sendRequestHead(requestHead, startBody: false))
254254
let responseHead = HTTPResponseHead(version: .http1_1, status: .switchingProtocols)
@@ -260,7 +260,7 @@ class HTTP1ConnectionStateMachineTests: XCTestCase {
260260
var state = HTTP1ConnectionStateMachine()
261261
XCTAssertEqual(state.channelActive(isWritable: true), .fireChannelActive)
262262
let requestHead = HTTPRequestHead(version: .http1_1, method: .GET, uri: "/")
263-
let metadata = RequestFramingMetadata(connectionClose: false, body: .none)
263+
let metadata = RequestFramingMetadata(connectionClose: false, body: .fixedSize(0))
264264
let newRequestAction = state.runNewRequest(head: requestHead, metadata: metadata)
265265
XCTAssertEqual(newRequestAction, .sendRequestHead(requestHead, startBody: false))
266266
let responseHead = HTTPResponseHead(version: .http1_1, status: .init(statusCode: 103, reasonPhrase: "Early Hints"))

0 commit comments

Comments
 (0)