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

Code before:
                switch element {
                case .data(let data):
                    return .fireChannelRead(data)
                case .inputClosed:
                    return .close
                }
            } else {
                self.state = .finished

                return .fireChannelReadCompleteAndRemoveHandler
            }

        case .modifying:
            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 were 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

Review comment (suggestion):
Naming NIT: Can we call this `inputClosed` instead please

Code after:
                self.state = .unbuffering(unbuffering)
                switch element {
                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`.