mirror of
https://github.com/apple/swift-nio-http2
synced 2026-11-25 04:47:50 +00:00
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:
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
+2
-2
@@ -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.
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user