Repository: apple/swift-nio
File: Sources/NIOHTTP1/NIOTypedHTTPServerUpgraderStateMachine.swift (Swift)

Code before:
            fatalError("Internal inconsistency in HTTPServerUpgradeStateMachine")
            
        }
    }

    @usableFromInline
    enum CloseInboundAction {
        case close
        case `continue`
    }

    @inlinable
    mutating func closeInbound() -> CloseInboundAction {
        switch self.state {
        case .initial:
            self.state = .finished
            return .close

        case .awaitingUpgrader(var awaitingUpgrader):
            if awaitingUpgrader.seenFirstRequest {
                // We should buffer the input close since we have seen the full request.
                awaitingUpgrader.buffer.append(.inputClosed)
                self.state = .awaitingUpgrader(awaitingUpgrader)
                return .continue
            } else {
                // We shouldn't buffer. This means we are still expecting HTTP parts.
                return .close
            }

        case .upgrading(var upgrading):
            upgrading.buffer.append(.inputClosed)
            self.state = .upgrading(upgrading)
            return .continue

        case .upgraderReady(var upgraderReady):
            upgraderReady.buffer.append(.inputClosed)
            self.state = .upgraderReady(upgraderReady)
            return .continue

        case .unbuffering(var unbuffering):
            unbuffering.buffer.append(.inputClosed)
            self.state = .unbuffering(unbuffering)
            return .continue

        case .modifying, .finished:
            return .continue
        }
    }
 
}
#endif

Review comment (suggestion):
NIT
```suggestion
                // We shouldn't buffer. This means we were still expecting HTTP parts.
```

Code after:
                case .data(let data):
                    return .fireChannelRead(data)
                case .inputClosed:
                    return .fireInputClosedEvent
                }
            } else {
                self.state = .finished

                return .fireChannelReadCompleteAndRemoveHandler
            }

        case .modifying:
            fatalError("Internal inconsistency in HTTPServerUpgradeStateMachine")

        }
    }

    @usableFromInline
    enum InputClosedAction {
        case close
        case `continue`
        case fireInputClosedEvent
    }

    @inlinable
    mutating func inputClosed() -> InputClosedAction {
        switch self.state {
        case .initial:
            self.state = .finished
            return .close

        case .awaitingUpgrader(var awaitingUpgrader):
            if awaitingUpgrader.seenFirstRequest {
                // We should buffer the input close since we have seen the full request.
                awaitingUpgrader.buffer.append(.inputClosed)
                self.state = .awaitingUpgrader(awaitingUpgrader)
                return .continue
            } else {
                // We shouldn't buffer. This means we were still expecting HTTP parts.
                return .close
            }

        case .upgrading(var upgrading):
            upgrading.buffer.append(.inputClosed)
            self.state = .upgrading(upgrading)
            return .continue

        case .upgraderReady:
            // if the state is `upgraderReady` we have received a `.head` but not an `.end`.
            // If input is closed then there is no way to move this forward so we should
            // close.