Skip to content

Commit 4979197

Browse files
committed
add two additional preconditions
1 parent 8c99c41 commit 4979197

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sources/AsyncHTTPClient/HTTPHandler.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,14 @@ extension TaskHandler: ChannelDuplexHandler {
840840
self.writeBody(request: request, context: context)
841841
}.flatMap {
842842
context.eventLoop.assertInEventLoop()
843+
844+
switch self.state {
845+
case .endOrError:
846+
preconditionFailure("unexpected state on body sent")
847+
default:
848+
break
849+
}
850+
843851
self.state = .bodySent
844852
if let expectedBodyLength = self.expectedBodyLength, expectedBodyLength != self.actualBodyLength {
845853
let error = HTTPClientError.bodyLengthMismatch
@@ -849,6 +857,14 @@ extension TaskHandler: ChannelDuplexHandler {
849857
return context.writeAndFlush(self.wrapOutboundOut(.end(nil)))
850858
}.map {
851859
context.eventLoop.assertInEventLoop()
860+
861+
switch self.state {
862+
case .endOrError:
863+
preconditionFailure("unexpected state on sent")
864+
default:
865+
break
866+
}
867+
852868
self.state = .sent
853869
self.callOutToDelegateFireAndForget(self.delegate.didSendRequest)
854870
}.flatMapErrorThrowing { error in

0 commit comments

Comments
 (0)