Add a location to each of 'NIOHTTP2Errors' (#247)

Motivation:

Without knowing where an error was thrown it can be unnecessarily
difficult to work out the reasons an application ended up in an error
state.

Modifications:

- Add a 'file' string to each of the 'NIOHTTP2Errors' denoting the file
  and line where an error was created
- Add static methods to create errors to 'NIOHTTP2Errors' defaulting
  file and line, this is unfortunately necessary as defaulting file and
  line in the `init` makes the defaulted and non-defaulted errors
  indistinguishable, and the compiler will pick the one with fewest
  defaulted values.
- Add equatable conformance manually so as to ignore 'file'
- Add backing storage to errors which no longer be stored in an existential
  container
- Add 'CustomStringConvertible' conformance to the errors using backing
  storage so that the 'file' is actually visible when converting the
  error
- Deprecate the old `init`s
- Fix all deprecation warnings

Result:

- NIOHTTP2Errors carry a 'file' with them indicating where they were
  created
This commit is contained in:
George Barnett authored and GitHub committed 2020-09-24 15:21:58 +01:00
1 parent 28d94c489d
commit 440d64d99a
33 files changed
+1598 -233

No files matched your search

@@ -618,7 +618,7 @@ extension HTTP2ConnectionStateMachine {
}
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -677,10 +677,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceSent, .quiescingPrefaceSent:
// If we're still waiting for the remote preface, they are not allowed to send us a HEADERS frame yet!
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -737,10 +737,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceReceived, .quiescingPrefaceReceived:
// If we're still waiting for the local preface, we are not allowed to send a HEADERS frame yet!
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -797,10 +797,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceSent, .quiescingPrefaceSent:
// If we're still waiting for the remote preface, we are not allowed to receive a DATA frame yet!
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -857,10 +857,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceReceived, .quiescingPrefaceReceived:
// If we're still waiting for the local preface, we are not allowed to send a DATA frame yet!
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -876,10 +876,10 @@ extension HTTP2ConnectionStateMachine {
return StateMachineResultWithEffect(result: .succeed, effect: nil)
case .idle, .prefaceSent, .quiescingPrefaceSent:
return StateMachineResultWithEffect(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return StateMachineResultWithEffect(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return StateMachineResultWithEffect(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return StateMachineResultWithEffect(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -895,10 +895,10 @@ extension HTTP2ConnectionStateMachine {
return .init(result: .succeed, effect: nil)
case .idle, .prefaceReceived, .quiescingPrefaceReceived:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -955,10 +955,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceSent, .quiescingPrefaceSent:
// We're waiting for the remote preface.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -1015,10 +1015,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceReceived, .quiescingPrefaceReceived:
// We're waiting for the local preface.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -1083,10 +1083,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceSent, .quiescingPrefaceSent:
// We're waiting for the remote preface.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -1118,7 +1118,7 @@ extension HTTP2ConnectionStateMachine {
case .remotelyQuiesced, .bothQuiescing:
// We have been quiesced, and may not create new streams.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.CreatedStreamAfterGoaway(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.createdStreamAfterGoaway(), type: .protocolError), effect: nil)
case .quiescingPrefaceSent(var state):
return self.avoidingStateMachineCoW { newState in
@@ -1129,10 +1129,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceReceived, .quiescingPrefaceReceived:
// We're waiting for the local preface.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -1150,10 +1150,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceSent, .quiescingPrefaceSent:
// We're waiting for the remote preface.
return (.init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil), .nothing)
return (.init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil), .nothing)
case .fullyQuiesced:
return (.init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil), .nothing)
return (.init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil), .nothing)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -1171,10 +1171,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceReceived, .quiescingPrefaceReceived:
// We're waiting for the local preface.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -1240,7 +1240,7 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceSent, .quiescingPrefaceSent:
// We're waiting for the preface.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced(var state):
return self.avoidingStateMachineCoW { newState in
@@ -1313,7 +1313,7 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceReceived, .quiescingPrefaceReceived:
// We're waiting for the preface.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced(var state):
return self.avoidingStateMachineCoW { newState in
@@ -1375,10 +1375,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceSent, .quiescingPrefaceSent:
// We're waiting for the preface.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -1432,10 +1432,10 @@ extension HTTP2ConnectionStateMachine {
case .idle, .prefaceReceived, .quiescingPrefaceReceived:
// We're waiting for the preface.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.MissingPreface(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.missingPreface(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -1521,7 +1521,7 @@ extension HTTP2ConnectionStateMachine {
}
case .fullyQuiesced:
return (.init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil), .nothing)
return (.init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil), .nothing)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -1561,10 +1561,10 @@ extension HTTP2ConnectionStateMachine {
}
case .idle, .prefaceSent, .prefaceReceived, .quiescingPrefaceReceived, .quiescingPrefaceSent:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ReceivedBadSettings(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.receivedBadSettings(), type: .protocolError), effect: nil)
case .fullyQuiesced:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.IOOnClosedConnection(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.ioOnClosedConnection(), type: .protocolError), effect: nil)
case .modifying:
preconditionFailure("Must not be left in modifying state")
@@ -1581,15 +1581,15 @@ extension HTTP2ConnectionStateMachine {
switch setting.parameter {
case .enablePush:
guard setting._value == 0 || setting._value == 1 else {
return .connectionError(underlyingError: NIOHTTP2Errors.InvalidSetting(setting: setting), type: .protocolError)
return .connectionError(underlyingError: NIOHTTP2Errors.invalidSetting(setting: setting), type: .protocolError)
}
case .initialWindowSize:
guard setting._value <= HTTP2FlowControlWindow.maxSize else {
return .connectionError(underlyingError: NIOHTTP2Errors.InvalidSetting(setting: setting), type: .flowControlError)
return .connectionError(underlyingError: NIOHTTP2Errors.invalidSetting(setting: setting), type: .flowControlError)
}
case .maxFrameSize:
guard setting._value >= (1 << 14) && setting._value <= ((1 << 24) - 1) else {
return .connectionError(underlyingError: NIOHTTP2Errors.InvalidSetting(setting: setting), type: .protocolError)
return .connectionError(underlyingError: NIOHTTP2Errors.invalidSetting(setting: setting), type: .protocolError)
}
default:
// All other settings have unrestricted ranges.
@@ -228,15 +228,15 @@ struct ConnectionStreamState {
/// Adjusts the stream state to reserve a client stream ID.
mutating func reserveClientStreamID(_ streamID: HTTP2StreamID) throws {
guard self.clientStreamCount < self.maxClientInitiatedStreams else {
throw NIOHTTP2Errors.MaxStreamsViolation()
throw NIOHTTP2Errors.maxStreamsViolation()
}
guard streamID > self.lastClientStreamID else {
throw NIOHTTP2Errors.StreamIDTooSmall()
throw NIOHTTP2Errors.streamIDTooSmall()
}
guard streamID.mayBeInitiatedBy(.client) else {
throw NIOHTTP2Errors.InvalidStreamIDForPeer()
throw NIOHTTP2Errors.invalidStreamIDForPeer()
}
self.lastClientStreamID = streamID
@@ -246,15 +246,15 @@ struct ConnectionStreamState {
/// Adjusts the stream state to reserve a server stream ID.
mutating func reserveServerStreamID(_ streamID: HTTP2StreamID) throws {
guard self.serverStreamCount < self.maxServerInitiatedStreams else {
throw NIOHTTP2Errors.MaxStreamsViolation()
throw NIOHTTP2Errors.maxStreamsViolation()
}
guard streamID > self.lastServerStreamID else {
throw NIOHTTP2Errors.StreamIDTooSmall()
throw NIOHTTP2Errors.streamIDTooSmall()
}
guard streamID.mayBeInitiatedBy(.server) else {
throw NIOHTTP2Errors.InvalidStreamIDForPeer()
throw NIOHTTP2Errors.invalidStreamIDForPeer()
}
self.lastServerStreamID = streamID
@@ -310,13 +310,13 @@ struct ConnectionStreamState {
case true where streamID > self.lastClientStreamID,
false where streamID > self.lastServerStreamID:
// The stream in question is idle.
return .connectionError(underlyingError: NIOHTTP2Errors.NoSuchStream(streamID: streamID), type: .protocolError)
return .connectionError(underlyingError: NIOHTTP2Errors.noSuchStream(streamID: streamID), type: .protocolError)
default:
// This stream must have already been closed.
if ignoreClosed {
return .ignoreFrame
return .ignoreFrame
} else {
return .connectionError(underlyingError: NIOHTTP2Errors.NoSuchStream(streamID: streamID), type: .streamClosed)
return .connectionError(underlyingError: NIOHTTP2Errors.noSuchStream(streamID: streamID), type: .streamClosed)
}
}
}
@@ -26,7 +26,7 @@ extension ReceivingGoawayState {
mutating func receiveGoAwayFrame(lastStreamID: HTTP2StreamID) -> StateMachineResultWithEffect {
guard lastStreamID.mayBeInitiatedBy(self.role) || lastStreamID == .rootStream || lastStreamID == .maxID else {
// The remote peer has sent a GOAWAY with an invalid stream ID.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.InvalidStreamIDForPeer(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.invalidStreamIDForPeer(), type: .protocolError), effect: nil)
}
let droppedStreams = self.streamState.dropAllStreamsWithIDHigherThan(lastStreamID, droppedLocally: false, initiatedBy: self.role)
@@ -39,12 +39,12 @@ extension ReceivingGoawayState where Self: RemotelyQuiescingState {
mutating func receiveGoAwayFrame(lastStreamID: HTTP2StreamID) -> StateMachineResultWithEffect {
guard lastStreamID.mayBeInitiatedBy(self.role) || lastStreamID == .rootStream || lastStreamID == .maxID else {
// The remote peer has sent a GOAWAY with an invalid stream ID.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.InvalidStreamIDForPeer(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.invalidStreamIDForPeer(), type: .protocolError), effect: nil)
}
if lastStreamID > self.lastLocalStreamID {
// The remote peer has attempted to raise the lastStreamID.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.RaisedGoawayLastStreamID(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.raisedGoawayLastStreamID(), type: .protocolError), effect: nil)
}
let droppedStreams = self.streamState.dropAllStreamsWithIDHigherThan(lastStreamID, droppedLocally: false, initiatedBy: self.role)
@@ -46,7 +46,7 @@ extension ReceivingPushPromiseState {
//
// Before any of this, though, we need to check whether the remote peer is even allowed to push!
guard self.peerMayPush else {
return StateMachineResultWithEffect(result: .connectionError(underlyingError: NIOHTTP2Errors.PushInViolationOfSetting(), type: .protocolError), effect: nil)
return StateMachineResultWithEffect(result: .connectionError(underlyingError: NIOHTTP2Errors.pushInViolationOfSetting(), type: .protocolError), effect: nil)
}
let validateHeaderBlock = self.headerBlockValidation == .enabled
@@ -75,7 +75,7 @@ extension ReceivingPushPromiseState where Self: LocallyQuiescingState {
mutating func receivePushPromise(originalStreamID: HTTP2StreamID, childStreamID: HTTP2StreamID, headers: HPACKHeaders) -> StateMachineResultWithEffect {
// This check is duplicated here, because the protocol error of violating this setting is more important than ignoring the frame.
guard self.peerMayPush else {
return StateMachineResultWithEffect(result: .connectionError(underlyingError: NIOHTTP2Errors.PushInViolationOfSetting(), type: .protocolError), effect: nil)
return StateMachineResultWithEffect(result: .connectionError(underlyingError: NIOHTTP2Errors.pushInViolationOfSetting(), type: .protocolError), effect: nil)
}
// If we're a client, the server is forbidden from initiating new streams, as we quiesced. However, RFC 7540 wants us to ignore this.
@@ -26,7 +26,7 @@ extension SendingGoawayState {
mutating func sendGoAwayFrame(lastStreamID: HTTP2StreamID) -> StateMachineResultWithEffect {
guard lastStreamID.mayBeInitiatedBy(self.peerRole) || lastStreamID == .rootStream || lastStreamID == .maxID else {
// The user has sent a GOAWAY with an invalid stream ID.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.InvalidStreamIDForPeer(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.invalidStreamIDForPeer(), type: .protocolError), effect: nil)
}
let droppedStreams = self.streamState.dropAllStreamsWithIDHigherThan(lastStreamID, droppedLocally: true, initiatedBy: self.peerRole)
@@ -39,12 +39,12 @@ extension SendingGoawayState where Self: LocallyQuiescingState {
mutating func sendGoAwayFrame(lastStreamID: HTTP2StreamID) -> StateMachineResultWithEffect {
guard lastStreamID.mayBeInitiatedBy(self.peerRole) || lastStreamID == .rootStream || lastStreamID == .maxID else {
// The user has sent a GOAWAY with an invalid stream ID.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.InvalidStreamIDForPeer(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.invalidStreamIDForPeer(), type: .protocolError), effect: nil)
}
if lastStreamID > self.lastRemoteStreamID {
// The user has attempted to raise the lastStreamID.
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.RaisedGoawayLastStreamID(), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.raisedGoawayLastStreamID(), type: .protocolError), effect: nil)
}
// Ok, this is a valid request, so we can now process it like .active.
@@ -45,7 +45,7 @@ extension SendingPushPromiseState {
// First, however, we need to check we can push at all!
guard self.mayPush else {
return StateMachineResultWithEffect(result: .connectionError(underlyingError: NIOHTTP2Errors.PushInViolationOfSetting(), type: .protocolError), effect: nil)
return StateMachineResultWithEffect(result: .connectionError(underlyingError: NIOHTTP2Errors.pushInViolationOfSetting(), type: .protocolError), effect: nil)
}
do {
@@ -91,7 +91,7 @@ struct HTTP2SettingsState {
/// - onValueChange: A callback that will be invoked once for each setting change.
mutating func receiveSettingsAck(onValueChange: OnValueChangeCallback) throws {
guard self.unacknowlegedSettingsFrames.count > 0 else {
throw NIOHTTP2Errors.ReceivedBadSettings()
throw NIOHTTP2Errors.receivedBadSettings()
}
try self.applySettings(self.unacknowlegedSettingsFrames.removeFirst(), onValueChange: onValueChange)
+2 -2
View File
@@ -31,7 +31,7 @@ extension ContentLengthVerifier {
let newContentLength = expectedContentLength - length
if newContentLength < 0 {
throw NIOHTTP2Errors.ContentLengthViolated()
throw NIOHTTP2Errors.contentLengthViolated()
}
self.expectedContentLength = newContentLength
}
@@ -42,7 +42,7 @@ extension ContentLengthVerifier {
case .none, .some(0):
break
default:
throw NIOHTTP2Errors.ContentLengthViolated()
throw NIOHTTP2Errors.contentLengthViolated()
}
}
}
+1 -1
View File
@@ -54,7 +54,7 @@ extension DOSHeuristics {
}
if self.receivedEmptyDataFrames > self.maximumSequentialEmptyDataFrames {
throw NIOHTTP2Errors.ExcessiveEmptyDataFrames()
throw NIOHTTP2Errors.excessiveEmptyDataFrames()
}
}
}
@@ -144,7 +144,7 @@ struct ConcurrentStreamBuffer {
// but doesn't match something in the buffer. As a result, it is an error for this frame to have a stream ID lower than or equal to the
// highest stream ID in the buffer: if it did, we should have found it when we searched above. If that constraint is breached, fail the write.
if let lastElement = self.bufferedFrames.last, frame.streamID <= lastElement.streamID {
throw NIOHTTP2Errors.StreamIDTooSmall()
throw NIOHTTP2Errors.streamIDTooSmall()
}
// Ok, the stream ID is fine: buffer this frame.
@@ -155,7 +155,7 @@ struct ConcurrentStreamBuffer {
// This buffer probably has a HEADERS frame in it, and we really don't want to violate the ordering requirements that implies, so we'll buffer this anyway.
// We still want StreamIDTooSmall protection here.
if frame.streamID <= lastElement.streamID {
throw NIOHTTP2Errors.StreamIDTooSmall()
throw NIOHTTP2Errors.streamIDTooSmall()
}
// Ok, the stream ID is fine: buffer this frame.
@@ -223,9 +223,9 @@ struct ConcurrentStreamBuffer {
// If we're currently unbuffering this stream, we need to pass the RST_STREAM frame on for correctness. If we aren't, just
// kill it.
if writeBuffer.currentlyUnblocking {
return .forwardAndDrop(writeBuffer.frames, NIOHTTP2Errors.StreamClosed(streamID: frame.streamID, errorCode: reason))
return .forwardAndDrop(writeBuffer.frames, NIOHTTP2Errors.streamClosed(streamID: frame.streamID, errorCode: reason))
} else {
return .succeedAndDrop(writeBuffer.frames, NIOHTTP2Errors.StreamClosed(streamID: frame.streamID, errorCode: reason))
return .succeedAndDrop(writeBuffer.frames, NIOHTTP2Errors.streamClosed(streamID: frame.streamID, errorCode: reason))
}
}
@@ -91,7 +91,7 @@ extension ControlFrameBuffer {
guard self.pendingControlFrames.count < self.maximumBufferSize else {
// Appending another frame would violate the maximum buffer size. We're storing too many frames here,
// we gotta move on.
throw NIOHTTP2Errors.ExcessiveOutboundFrameBuffering()
throw NIOHTTP2Errors.excessiveOutboundFrameBuffering()
}
self.pendingControlFrames.append(PendingControlFrame(frame: frame, promise: promise))
}
@@ -48,7 +48,7 @@ internal struct OutboundFlowControlBuffer {
if !self.streamDataBuffers[frame.streamID].apply({ $0.dataBuffer.bufferWrite((.data(body), promise)) }) {
// We don't have this stream ID. This is an internal error, but we won't precondition on it as
// it can happen due to channel handler misconfiguration or other weirdness. We'll just complain.
throw NIOHTTP2Errors.NoSuchStream(streamID: frame.streamID)
throw NIOHTTP2Errors.noSuchStream(streamID: frame.streamID)
}
return .nothing
case .headers(let headerContent):
@@ -191,7 +191,7 @@ extension OutboundFlowControlBuffer {
// RFC 7540 § 5.3, where we can, so this hook is already in place for us to extend later.
if streamID == priorityData.dependency {
// Streams may not depend on themselves!
throw NIOHTTP2Errors.PriorityCycle(streamID: streamID)
throw NIOHTTP2Errors.priorityCycle(streamID: streamID)
}
}
}
@@ -58,7 +58,7 @@ fileprivate enum BlockSection {
case (.headers, .pseudoHeaderField):
// This is an error: it's not allowed to send a pseudo-header field once a regular
// header field has been sent.
throw NIOHTTP2Errors.PseudoHeaderAfterRegularHeader(":\(field.baseName)")
throw NIOHTTP2Errors.pseudoHeaderAfterRegularHeader(":\(field.baseName)")
}
}
}
@@ -97,7 +97,7 @@ extension HeaderBlockValidator {
// and at least the mandatory set.
guard validator.allowedPseudoHeaderFields.isSuperset(of: seenPseudoHeaders) &&
validator.mandatoryPseudoHeaderFields.isSubset(of: seenPseudoHeaders) else {
throw NIOHTTP2Errors.InvalidPseudoHeaders(block)
throw NIOHTTP2Errors.invalidPseudoHeaders(block)
}
}
}
@@ -153,7 +153,7 @@ extension RequestBlockValidator: HeaderBlockValidator {
case .path:
// This is a path pseudo-header. It must not be empty.
if value.utf8.count == 0 {
throw NIOHTTP2Errors.EmptyPathHeader()
throw NIOHTTP2Errors.emptyPathHeader()
}
default:
break
@@ -163,7 +163,7 @@ extension RequestBlockValidator: HeaderBlockValidator {
// We want to check that if the TE header field is present, it only contains "trailers".
if name.baseName == "te" && value != "trailers" {
throw NIOHTTP2Errors.ForbiddenHeaderField(name: String(name.baseName), value: value)
throw NIOHTTP2Errors.forbiddenHeaderField(name: String(name.baseName), value: value)
}
}
}
@@ -253,7 +253,7 @@ extension HeaderFieldName {
}
guard baseNameBytes.isValidFieldName else {
throw NIOHTTP2Errors.InvalidHTTP2HeaderFieldName(fieldName)
throw NIOHTTP2Errors.invalidHTTP2HeaderFieldName(fieldName)
}
}
@@ -272,7 +272,7 @@ extension HeaderFieldName {
switch self.baseName {
case "connection", "transfer-encoding", "proxy-connection":
throw NIOHTTP2Errors.ForbiddenHeaderField(name: String(self.baseName), value: value)
throw NIOHTTP2Errors.forbiddenHeaderField(name: String(self.baseName), value: value)
default:
return
}
@@ -382,11 +382,11 @@ extension PseudoHeaders {
}
guard let pseudoHeaderType = PseudoHeaders(headerFieldName: name) else {
throw NIOHTTP2Errors.UnknownPseudoHeader(":\(name.baseName)")
throw NIOHTTP2Errors.unknownPseudoHeader(":\(name.baseName)")
}
if self.contains(pseudoHeaderType) {
throw NIOHTTP2Errors.DuplicatePseudoHeader(":\(name.baseName)")
throw NIOHTTP2Errors.duplicatePseudoHeader(":\(name.baseName)")
}
self.formUnion(pseudoHeaderType)
+27 -19
View File
@@ -203,13 +203,13 @@ extension NIOHTTP2Handler {
do {
return try self.frameDecoder.nextFrame()
} catch InternalError.codecError(let code) {
self.inboundConnectionErrorTriggered(context: context, underlyingError: NIOHTTP2Errors.UnableToParseFrame(), reason: code)
self.inboundConnectionErrorTriggered(context: context, underlyingError: NIOHTTP2Errors.unableToParseFrame(), reason: code)
return nil
} catch is NIOHTTP2Errors.BadClientMagic {
self.inboundConnectionErrorTriggered(context: context, underlyingError: NIOHTTP2Errors.BadClientMagic(), reason: .protocolError)
self.inboundConnectionErrorTriggered(context: context, underlyingError: NIOHTTP2Errors.badClientMagic(), reason: .protocolError)
return nil
} catch is NIOHTTP2Errors.ExcessivelyLargeHeaderBlock {
self.inboundConnectionErrorTriggered(context: context, underlyingError: NIOHTTP2Errors.ExcessivelyLargeHeaderBlock(), reason: .protocolError)
self.inboundConnectionErrorTriggered(context: context, underlyingError: NIOHTTP2Errors.excessivelyLargeHeaderBlock(), reason: .protocolError)
return nil
} catch {
self.inboundConnectionErrorTriggered(context: context, underlyingError: error, reason: .internalError)
@@ -470,7 +470,7 @@ extension NIOHTTP2Handler {
do {
extraFrameData = try self.frameEncoder.encode(frame: frame, to: &self.writeBuffer)
} catch InternalError.codecError {
self.outboundErrorTriggered(context: context, promise: promise, underlyingError: NIOHTTP2Errors.UnableToSerializeFrame())
self.outboundErrorTriggered(context: context, promise: promise, underlyingError: NIOHTTP2Errors.unableToSerializeFrame())
return
} catch {
self.outboundErrorTriggered(context: context, promise: promise, underlyingError: error)
@@ -509,11 +509,8 @@ extension NIOHTTP2Handler {
self.inboundEventBuffer.pendingUserEvent(StreamClosedEvent(streamID: streamClosedData.streamID, reason: streamClosedData.reason))
self.inboundEventBuffer.pendingUserEvent(NIOHTTP2WindowUpdatedEvent(streamID: .rootStream, inboundWindowSize: streamClosedData.remoteConnectionWindowSize, outboundWindowSize: streamClosedData.localConnectionWindowSize))
let failedWrites = self.outboundBuffer.streamClosed(streamClosedData.streamID)
let error = NIOHTTP2Errors.StreamClosed(streamID: streamClosedData.streamID, errorCode: streamClosedData.reason ?? .cancel)
for promise in failedWrites {
promise?.fail(error)
}
let droppedPromises = self.outboundBuffer.streamClosed(streamClosedData.streamID)
self.failDroppedPromises(droppedPromises, streamID: streamClosedData.streamID, errorCode: streamClosedData.reason ?? .cancel)
case .streamCreated(let streamCreatedData):
self.outboundBuffer.streamCreated(streamCreatedData.streamID, initialWindowSize: streamCreatedData.localStreamWindowSize.map(UInt32.init) ?? 0)
self.inboundEventBuffer.pendingUserEvent(NIOHTTP2StreamCreatedEvent(streamID: streamCreatedData.streamID,
@@ -523,11 +520,8 @@ extension NIOHTTP2Handler {
for droppedStream in streamClosureData.closedStreams {
self.inboundEventBuffer.pendingUserEvent(StreamClosedEvent(streamID: droppedStream, reason: .cancel))
let failedWrites = self.outboundBuffer.streamClosed(droppedStream)
let error = NIOHTTP2Errors.StreamClosed(streamID: droppedStream, errorCode: .cancel)
for promise in failedWrites {
promise?.fail(error)
}
let droppedPromises = self.outboundBuffer.streamClosed(droppedStream)
self.failDroppedPromises(droppedPromises, streamID: droppedStream, errorCode: .cancel)
}
case .flowControlChange(let change):
self.outboundBuffer.connectionWindowSize = change.localConnectionWindowSize
@@ -538,11 +532,8 @@ extension NIOHTTP2Handler {
}
case .streamCreatedAndClosed(let cAndCData):
self.outboundBuffer.streamCreated(cAndCData.streamID, initialWindowSize: 0)
let failedWrites = self.outboundBuffer.streamClosed(cAndCData.streamID)
let error = NIOHTTP2Errors.StreamClosed(streamID: cAndCData.streamID, errorCode: .cancel)
for promise in failedWrites {
promise?.fail(error)
}
let droppedPromises = self.outboundBuffer.streamClosed(cAndCData.streamID)
self.failDroppedPromises(droppedPromises, streamID: cAndCData.streamID, errorCode: .cancel)
case .remoteSettingsChanged(let settingsChange):
if settingsChange.streamWindowSizeChange != 0 {
self.outboundBuffer.initialWindowSizeChanged(settingsChange.streamWindowSizeChange)
@@ -583,6 +574,23 @@ extension NIOHTTP2Handler {
context.flush()
}
}
/// Fails any promises in the given collection with a 'StreamClosed' error.
private func failDroppedPromises(_ promises: CompoundOutboundBuffer.DroppedPromisesCollection,
streamID: HTTP2StreamID,
errorCode: HTTP2ErrorCode,
file: String = #file, line: UInt = #line) {
// 'NIOHTTP2Errors.streamClosed' always allocates, if there are no promises then there's no
// need to create the error.
guard promises.contains(where: { $0 != nil }) else {
return
}
let error = NIOHTTP2Errors.streamClosed(streamID: streamID, errorCode: errorCode, file: file, line: line)
for promise in promises {
promise?.fail(error)
}
}
}
File diff suppressed because it is too large. Load diff
@@ -87,14 +87,14 @@ struct HTTP2FlowControlWindow {
assert(amount <= HTTP2FlowControlWindow.maxIncrement)
guard amount >= 1 else {
throw NIOHTTP2Errors.InvalidWindowIncrementSize()
throw NIOHTTP2Errors.invalidWindowIncrementSize()
}
// We now need to bounds check to confirm that our window size will remain in the valid range. We use
// subtraction to avoid integer overflow. Note that if the current window size is negative then all window
// update increments are valid.
guard (self.windowSize < 0) || (HTTP2FlowControlWindow.maxSize - self.windowSize >= amount) else {
throw NIOHTTP2Errors.InvalidFlowControlWindowSize(delta: Int(amount), currentWindowSize: Int(self.windowSize))
throw NIOHTTP2Errors.invalidFlowControlWindowSize(delta: Int(amount), currentWindowSize: Int(self.windowSize))
}
self.windowSize += Int32(amount)
@@ -116,7 +116,7 @@ struct HTTP2FlowControlWindow {
assert(amount >= -(Int32.max))
guard (self.windowSize < 0) || (HTTP2FlowControlWindow.maxSize - self.windowSize >= amount) else {
throw NIOHTTP2Errors.InvalidFlowControlWindowSize(delta: Int(amount), currentWindowSize: Int(self.windowSize))
throw NIOHTTP2Errors.invalidFlowControlWindowSize(delta: Int(amount), currentWindowSize: Int(self.windowSize))
}
self.windowSize += amount
@@ -134,7 +134,7 @@ struct HTTP2FlowControlWindow {
let size = Int32(size)
guard self.windowSize >= size else {
throw NIOHTTP2Errors.FlowControlViolation()
throw NIOHTTP2Errors.flowControlViolation()
}
self.windowSize -= size
+6 -6
View File
@@ -326,7 +326,7 @@ struct HTTP2FrameDecoder {
}
guard clientMagic == HTTP2FrameDecoder.clientMagicBytes else {
throw NIOHTTP2Errors.BadClientMagic()
throw NIOHTTP2Errors.badClientMagic()
}
self.state = .accumulatingFrameHeader(.init(unusedBytes: state.pendingBytes))
@@ -349,7 +349,7 @@ struct HTTP2FrameDecoder {
// Not a DATA frame. Before we move on, do a quick preflight: if this frame header is for a frame that will
// definitely violate SETTINGS_MAX_HEADER_LIST_SIZE, quit now.
if header.type == 1 && header.length > self.headerDecoder.maxHeaderListSize {
throw NIOHTTP2Errors.ExcessivelyLargeHeaderBlock()
throw NIOHTTP2Errors.excessivelyLargeHeaderBlock()
}
self.state = .accumulatingData(AccumulatingPayloadParserState(fromIdle: state, header: header))
@@ -572,7 +572,7 @@ struct HTTP2FrameDecoder {
// Check whether there is any possibility of this payload decompressing and fitting in max header list size.
// If there isn't, kill it.
guard state.accumulatedPayload.readableBytes + header.length <= self.headerDecoder.maxHeaderListSize else {
throw NIOHTTP2Errors.ExcessivelyLargeHeaderBlock()
throw NIOHTTP2Errors.excessivelyLargeHeaderBlock()
}
self.state = .accumulatingContinuationPayload(AccumulatingContinuationPayloadParserState(fromAccumulatingHeaderBlockFragments: state, continuationHeader: header))
@@ -1031,7 +1031,7 @@ struct HTTP2FrameEncoder {
case .data(let dataContent):
if dataContent.paddingBytes != nil {
// we don't support sending padded frames just now
throw NIOHTTP2Errors.Unsupported(info: "Padding is not supported on sent frames at this time")
throw NIOHTTP2Errors.unsupported(info: "Padding is not supported on sent frames at this time")
}
if dataContent.endStream {
@@ -1043,7 +1043,7 @@ struct HTTP2FrameEncoder {
case .headers(let headerData):
if headerData.paddingBytes != nil {
// we don't support sending padded frames just now
throw NIOHTTP2Errors.Unsupported(info: "Padding is not supported on sent frames at this time")
throw NIOHTTP2Errors.unsupported(info: "Padding is not supported on sent frames at this time")
}
flags.insert(.endHeaders)
@@ -1099,7 +1099,7 @@ struct HTTP2FrameEncoder {
case .pushPromise(let pushPromiseData):
if pushPromiseData.paddingBytes != nil {
// we don't support sending padded frames just now
throw NIOHTTP2Errors.Unsupported(info: "Padding is not supported on sent frames at this time")
throw NIOHTTP2Errors.unsupported(info: "Padding is not supported on sent frames at this time")
}
let streamVal: UInt32 = UInt32(pushPromiseData.pushedStreamID)
+1 -1
View File
@@ -198,7 +198,7 @@ extension Channel {
case .negotiated:
// We negotiated something that isn't HTTP/1.1. This is a bad scene, and is a good indication
// of a user configuration error. We're going to close the connection directly.
return self.close().flatMap { self.eventLoop.makeFailedFuture(NIOHTTP2Errors.InvalidALPNToken()) }
return self.close().flatMap { self.eventLoop.makeFailedFuture(NIOHTTP2Errors.invalidALPNToken()) }
}
}
+2 -2
View File
@@ -362,7 +362,7 @@ final class HTTP2StreamChannel: Channel, ChannelCore {
if let streamID = self.streamID {
return streamID as! Option.Value
} else {
throw NIOHTTP2Errors.NoStreamIDAvailable()
throw NIOHTTP2Errors.noStreamIDAvailable()
}
case _ as ChannelOptions.Types.AutoReadOption:
return self.autoRead as! Option.Value
@@ -785,7 +785,7 @@ internal extension HTTP2StreamChannel {
if let reason = reason {
// To receive from the network, it must be safe to force-unwrap here.
let err = NIOHTTP2Errors.StreamClosed(streamID: self.streamID!, errorCode: reason)
let err = NIOHTTP2Errors.streamClosed(streamID: self.streamID!, errorCode: reason)
self.errorEncountered(error: err)
} else {
self.closedCleanly()
@@ -99,7 +99,7 @@ public final class HTTP2StreamMultiplexer: ChannelInboundHandler, ChannelOutboun
} else {
// This frame is for a stream we know nothing about. We can't do much about it, so we
// are going to fire an error and drop the frame.
let error = NIOHTTP2Errors.NoSuchStream(streamID: streamID)
let error = NIOHTTP2Errors.noSuchStream(streamID: streamID)
context.fireErrorCaught(error)
}
}
+5 -5
View File
@@ -600,7 +600,7 @@ internal extension HTTPResponseHead {
// A response head should have only one psuedo-header. We strip it off.
let statusHeader = try headers.peekPseudoHeader(name: ":status")
guard let integerStatus = Int(statusHeader, radix: 10) else {
throw NIOHTTP2Errors.InvalidStatusValue(statusHeader)
throw NIOHTTP2Errors.invalidStatusValue(statusHeader)
}
let status = HTTPResponseStatus(statusCode: integerStatus)
self.init(version: .init(major: 2, minor: 0), status: status, headers: HTTPHeaders(regularHeadersFrom: headers))
@@ -622,7 +622,7 @@ extension HPACKHeaders {
for (fieldName, fieldValue, _) in self {
if name == fieldName {
guard headerValue == nil else {
throw NIOHTTP2Errors.DuplicatePseudoHeader(name)
throw NIOHTTP2Errors.duplicatePseudoHeader(name)
}
headerValue = fieldValue
}
@@ -631,7 +631,7 @@ extension HPACKHeaders {
if let headerValue = headerValue {
return headerValue
} else {
throw NIOHTTP2Errors.MissingPseudoHeader(name)
throw NIOHTTP2Errors.missingPseudoHeader(name)
}
}
}
@@ -660,7 +660,7 @@ extension HTTPHeaders {
for header in requestHead.headers {
if header.name.lowercased() == "host" {
if authorityHeader != nil {
throw NIOHTTP2Errors.DuplicateHostHeader()
throw NIOHTTP2Errors.duplicateHostHeader()
}
authorityHeader = header.value
@@ -671,7 +671,7 @@ extension HTTPHeaders {
// Now we go back and fill in the authority header.
guard let actualAuthorityHeader = authorityHeader else {
throw NIOHTTP2Errors.MissingHostHeader()
throw NIOHTTP2Errors.missingHostHeader()
}
newHeaders[3].1 = actualAuthorityHeader
+12 -12
View File
@@ -383,9 +383,9 @@ extension HTTP2StreamStateMachine {
// seems reasonable to me: specifically, if we have a stream to fail, fail it, otherwise treat
// the error as connection scoped.)
case .idle(.server, _, _), .closed:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.BadStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.badStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
case .reservedRemote, .halfClosedLocalPeerIdle, .halfClosedLocalPeerActive:
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.BadStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.badStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
}
} catch let error where error is NIOHTTP2Errors.ContentLengthViolated {
return .init(result: .streamError(streamID: self.streamID, underlyingError: error, type: .protocolError), effect: nil)
@@ -514,9 +514,9 @@ extension HTTP2StreamStateMachine {
// seems reasonable to me: specifically, if we have a stream to fail, fail it, otherwise treat
// the error as connection scoped.)
case .idle(.client, _, _), .closed:
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.BadStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.badStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
case .reservedLocal, .halfClosedRemoteLocalIdle, .halfClosedRemoteLocalActive:
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.BadStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.badStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
}
} catch let error where error is NIOHTTP2Errors.ContentLengthViolated {
return .init(result: .streamError(streamID: self.streamID, underlyingError: error, type: .protocolError), effect: nil)
@@ -586,7 +586,7 @@ extension HTTP2StreamStateMachine {
// Sending a DATA frame outside any of these states is a stream error of type STREAM_CLOSED (RFC7540 § 6.1)
case .idle, .halfOpenRemoteLocalIdle, .reservedLocal, .reservedRemote, .halfClosedLocalPeerIdle,
.halfClosedLocalPeerActive, .halfClosedRemoteLocalIdle, .closed:
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.BadStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .streamClosed), effect: nil)
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.badStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .streamClosed), effect: nil)
}
} catch let error where error is NIOHTTP2Errors.FlowControlViolation {
return .init(result: .streamError(streamID: self.streamID, underlyingError: error, type: .flowControlError), effect: nil)
@@ -657,7 +657,7 @@ extension HTTP2StreamStateMachine {
// Receiving a DATA frame outside any of these states is a stream error of type STREAM_CLOSED (RFC7540 § 6.1)
case .idle, .halfOpenLocalPeerIdle, .reservedLocal, .reservedRemote, .halfClosedLocalPeerIdle,
.halfClosedRemoteLocalActive, .halfClosedRemoteLocalIdle, .closed:
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.BadStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .streamClosed), effect: nil)
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.badStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .streamClosed), effect: nil)
}
} catch let error where error is NIOHTTP2Errors.FlowControlViolation {
return .init(result: .streamError(streamID: self.streamID, underlyingError: error, type: .flowControlError), effect: nil)
@@ -693,7 +693,7 @@ extension HTTP2StreamStateMachine {
.fullyOpen(localRole: .client, localContentLength: _, remoteContentLength: _, localWindow: _, remoteWindow: _),
.halfClosedRemoteLocalActive(localRole: .client, initiatedBy: _, localContentLength: _, localWindow: _),
.halfClosedRemoteLocalActive(localRole: .server, initiatedBy: .server, localContentLength: _, localWindow: _):
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.BadStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.badStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
}
}
@@ -720,7 +720,7 @@ extension HTTP2StreamStateMachine {
.fullyOpen(localRole: .server, localContentLength: _, remoteContentLength: _, localWindow: _, remoteWindow: _),
.halfClosedLocalPeerActive(localRole: .server, initiatedBy: _, remoteContentLength: _, remoteWindow: _),
.halfClosedLocalPeerActive(localRole: .client, initiatedBy: .server, remoteContentLength: _, remoteWindow: _):
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.BadStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.badStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
}
}
@@ -769,7 +769,7 @@ extension HTTP2StreamStateMachine {
windowEffect = .windowSizeChange(.init(streamID: self.streamID, localStreamWindowSize: nil, remoteStreamWindowSize: Int(remoteWindow)))
case .idle, .reservedLocal, .halfClosedRemoteLocalIdle, .halfClosedRemoteLocalActive, .closed:
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.BadStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.badStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
}
} catch let error where error is NIOHTTP2Errors.InvalidFlowControlWindowSize {
return .init(result: .streamError(streamID: self.streamID, underlyingError: error, type: .flowControlError), effect: nil)
@@ -833,7 +833,7 @@ extension HTTP2StreamStateMachine {
windowEffect = nil
case .idle, .reservedRemote, .closed:
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.BadStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
return .init(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.badStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
}
} catch let error where error is NIOHTTP2Errors.InvalidFlowControlWindowSize {
return .init(result: .streamError(streamID: self.streamID, underlyingError: error, type: .flowControlError), effect: nil)
@@ -856,7 +856,7 @@ extension HTTP2StreamStateMachine {
mutating func receiveRstStream(reason: HTTP2ErrorCode) -> StateMachineResultWithStreamEffect {
// We can receive RST_STREAM frames in any state but idle.
if case .idle = self.state {
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.BadStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
return .init(result: .connectionError(underlyingError: NIOHTTP2Errors.badStreamStateTransition(from: NIOHTTP2StreamState.get(self.state)), type: .protocolError), effect: nil)
}
self.state = .closed(reason: reason)
@@ -1004,7 +1004,7 @@ extension HTTP2StreamStateMachine {
// End stream must be set on trailers.
guard endStream else {
return StateMachineResultWithStreamEffect(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.TrailersWithoutEndStream(streamID: self.streamID), type: .protocolError), effect: nil)
return StateMachineResultWithStreamEffect(result: .streamError(streamID: self.streamID, underlyingError: NIOHTTP2Errors.trailersWithoutEndStream(streamID: self.streamID), type: .protocolError), effect: nil)
}
self.state = target