Skip to content

Commit 2c49141

Browse files
committed
Code review
1 parent f64ae5f commit 2c49141

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

‎Sources/AsyncHTTPClient/ConnectionPool/HTTPRequestStateMachine+Demand.swift‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ extension HTTPRequestStateMachine{
4040

4141
privatevarstate:State
4242

43-
init(expectingBody:Bool){
44-
self.state =.waitingForBytes(CircularBuffer(initialCapacity: expectingBody ?16:0))
43+
init(){
44+
self.state =.waitingForBytes(CircularBuffer())
4545
}
4646

4747
mutatingfunc receivedBodyPart(_ body:ByteBuffer){
@@ -137,8 +137,6 @@ extension HTTPRequestStateMachine{
137137
mutatingfunc end()->CircularBuffer<ByteBuffer>{
138138
switchself.state {
139139
case.waitingForBytes(let buffer):
140-
// This should never happen. But we don't want to precondition this behavior. Let's just
141-
// pass the read event on
142140
return buffer
143141

144142
case.waitingForReadOrDemand,

‎Sources/AsyncHTTPClient/ConnectionPool/HTTPRequestStateMachine.swift‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -444,43 +444,34 @@ struct HTTPRequestStateMachine{
444444
return.wait
445445
}
446446

447-
varexpectingBody:Bool=false
448-
iflet length = head.headers.first(name:"content-length").flatMap({Int($0)}){
449-
if length >0{
450-
expectingBody =true
451-
}
452-
}elseif head.headers.contains(name:"transfer-encoding"){
453-
expectingBody =true
454-
}
455-
456447
switchself.state {
457448
case.initialized,.waitForChannelToBecomeWritable:
458449
preconditionFailure("How can we receive a response head before sending a request head ourselves")
459450

460451
case.running(.streaming(let expectedBodyLength,let sentBodyBytes, producer:.paused),.waitingForHead):
461452
self.state =.running(
462453
.streaming(expectedBodyLength: expectedBodyLength, sentBodyBytes: sentBodyBytes, producer:.paused),
463-
.receivingBody(head,.init(expectingBody: expectingBody))
454+
.receivingBody(head,.init())
464455
)
465456
return.forwardResponseHead(head, pauseRequestBodyStream:false)
466457

467458
case.running(.streaming(let expectedBodyLength,let sentBodyBytes, producer:.producing),.waitingForHead):
468459
if head.status.code >=300{
469460
self.state =.running(
470461
.streaming(expectedBodyLength: expectedBodyLength, sentBodyBytes: sentBodyBytes, producer:.paused),
471-
.receivingBody(head,.init(expectingBody: expectingBody))
462+
.receivingBody(head,.init())
472463
)
473464
return.forwardResponseHead(head, pauseRequestBodyStream:true)
474465
}else{
475466
self.state =.running(
476467
.streaming(expectedBodyLength: expectedBodyLength, sentBodyBytes: sentBodyBytes, producer:.producing),
477-
.receivingBody(head,.init(expectingBody: expectingBody))
468+
.receivingBody(head,.init())
478469
)
479470
return.forwardResponseHead(head, pauseRequestBodyStream:false)
480471
}
481472

482473
case.running(.endSent,.waitingForHead):
483-
self.state =.running(.endSent,.receivingBody(head,.init(expectingBody: expectingBody)))
474+
self.state =.running(.endSent,.receivingBody(head,.init()))
484475
return.forwardResponseHead(head, pauseRequestBodyStream:false)
485476

486477
case.running(_,.receivingBody),.running(_,.endReceived),.finished:

0 commit comments

Comments
(0)