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
+1
View File
@@ -44,6 +44,7 @@ class LinuxMainRunnerImpl: LinuxMainRunner {
testCase(HPACKCodingTests.allTests),
testCase(HPACKIntegrationTests.allTests),
testCase(HPACKRegressionTests.allTests),
testCase(HTTP2ErrorTests.allTests),
testCase(HTTP2FrameParserTests.allTests),
testCase(HTTP2FramePayloadStreamMultiplexerTests.allTests),
testCase(HTTP2FramePayloadToHTTP1CodecTests.allTests),
@@ -149,7 +149,7 @@ final class CompoundOutboundBufferTest: XCTestCase {
// Ok, now we complete stream 1. This makes the next frame elegible for emission.
XCTAssertEqual(buffer.streamClosed(1).count, 0)
buffer.nextFlushedWritableFrame(channelWritable: true).assertError(NIOHTTP2Errors.NoSuchStream(streamID: 3))
buffer.nextFlushedWritableFrame(channelWritable: true).assertError(NIOHTTP2Errors.noSuchStream(streamID: 3))
}
func testBufferedFrameDrops() {
@@ -181,7 +181,7 @@ final class CompoundOutboundBufferTest: XCTestCase {
future.map {
results[idx] = true
}.whenFailure { error in
XCTAssertEqual(error as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.StreamClosed(streamID: 3, errorCode: .protocolError))
XCTAssertEqual(error as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.streamClosed(streamID: 3, errorCode: .protocolError))
results[idx] = false
}
}
@@ -192,13 +192,13 @@ final class CompoundOutboundBufferTest: XCTestCase {
// Now, fail stream one.
for promise in buffer.streamClosed(1) {
promise?.fail(NIOHTTP2Errors.StreamClosed(streamID: 3, errorCode: .protocolError))
promise?.fail(NIOHTTP2Errors.streamClosed(streamID: 3, errorCode: .protocolError))
}
XCTAssertEqual(results, [true, false, nil, nil])
// Now fail stream three.
for promise in buffer.streamClosed(3) {
promise?.fail(NIOHTTP2Errors.StreamClosed(streamID: 3, errorCode: .protocolError))
promise?.fail(NIOHTTP2Errors.streamClosed(streamID: 3, errorCode: .protocolError))
}
XCTAssertEqual(results, [true, false, false, false])
}
@@ -207,10 +207,10 @@ final class CompoundOutboundBufferTest: XCTestCase {
var buffer = CompoundOutboundBuffer(mode: .client, initialMaxOutboundStreams: 1, maxBufferedControlFrames: 1000)
XCTAssertThrowsError(try buffer.priorityUpdate(streamID: 1, priorityData: .init(exclusive: false, dependency: 1, weight: 36))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.PriorityCycle(streamID: 1))
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.priorityCycle(streamID: 1))
}
XCTAssertThrowsError(try buffer.priorityUpdate(streamID: 1, priorityData: .init(exclusive: true, dependency: 1, weight: 36))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.PriorityCycle(streamID: 1))
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.priorityCycle(streamID: 1))
}
}
@@ -253,7 +253,7 @@ final class ConcurrentStreamBufferTests: XCTestCase {
promise.map {
writeStatus[idx] = true
}.whenFailure { error in
XCTAssertEqual(error as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.StreamClosed(streamID: 3, errorCode: .cancel))
XCTAssertEqual(error as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.streamClosed(streamID: 3, errorCode: .cancel))
writeStatus[idx] = false
}
}
@@ -284,7 +284,7 @@ final class ConcurrentStreamBufferTests: XCTestCase {
write.1?.fail(error)
}
XCTAssertEqual(error, NIOHTTP2Errors.StreamClosed(streamID: 3, errorCode: .cancel))
XCTAssertEqual(error, NIOHTTP2Errors.streamClosed(streamID: 3, errorCode: .cancel))
XCTAssertEqual(writeStatus, Array(repeating: true as Bool?, count: 15) + Array(repeating: false as Bool?, count: 15))
}
@@ -309,7 +309,7 @@ final class ConcurrentStreamBufferTests: XCTestCase {
promise.map {
writeStatus[idx] = true
}.whenFailure { error in
XCTAssertEqual(error as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.StreamClosed(streamID: 3, errorCode: .cancel))
XCTAssertEqual(error as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.streamClosed(streamID: 3, errorCode: .cancel))
writeStatus[idx] = false
}
}
@@ -416,7 +416,7 @@ final class ConcurrentStreamBufferTests: XCTestCase {
promise.map {
writeStatus[idx] = true
}.whenFailure { error in
XCTAssertEqual(error as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.StreamClosed(streamID: 3, errorCode: .protocolError))
XCTAssertEqual(error as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.streamClosed(streamID: 3, errorCode: .protocolError))
writeStatus[idx] = false
}
}
@@ -435,7 +435,7 @@ final class ConcurrentStreamBufferTests: XCTestCase {
return
}
for (_, promise) in droppedFrames {
promise?.fail(NIOHTTP2Errors.StreamClosed(streamID: 3, errorCode: .protocolError))
promise?.fail(NIOHTTP2Errors.streamClosed(streamID: 3, errorCode: .protocolError))
}
XCTAssertEqual(writeStatus, Array(repeating: false, count: 15))
@@ -264,7 +264,7 @@ class ConnectionStateMachineTests: XCTestCase {
self.server = savedServerState
// Test that BadStreamStateTransition conforms to CustomStringConvertible
XCTAssertEqual(lastBadStreamStateTransition?.description, "BadStreamStateTransition in state halfClosedLocalPeerActive")
XCTAssertTrue(lastBadStreamStateTransition!.description.starts(with: "BadStreamStateTransition(fromState: halfClosedLocalPeerActive"))
}
func testOpeningConnectionWhileServerPreambleMissing() {
@@ -101,7 +101,7 @@ final class ControlFrameBufferTests: XCTestCase {
XCTAssertNoThrow(try buffer.processOutboundFrame(.headers, promise: nil, channelWritable: false).assertNothing())
}
XCTAssertThrowsError(try buffer.processOutboundFrame(.headers, promise: nil, channelWritable: false)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessiveOutboundFrameBuffering, NIOHTTP2Errors.ExcessiveOutboundFrameBuffering())
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessiveOutboundFrameBuffering, NIOHTTP2Errors.excessiveOutboundFrameBuffering())
}
}
}
@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
//
// HTTP2ErrorTests+XCTest.swift
//
import XCTest
///
/// NOTE: This file was generated by generate_linux_tests.rb
///
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
///
extension HTTP2ErrorTests {
@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
static var allTests : [(String, (HTTP2ErrorTests) -> () throws -> Void)] {
return [
("testEquatableExcludesFileAndLine", testEquatableExcludesFileAndLine),
("testFitsInAnExistentialContainer", testFitsInAnExistentialContainer),
]
}
}
+236
View File
@@ -0,0 +1,236 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2020 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import XCTest
import NIOHTTP2
class HTTP2ErrorTests: XCTestCase {
func testEquatableExcludesFileAndLine() throws {
XCTAssertEqual(NIOHTTP2Errors.excessiveOutboundFrameBuffering(),
NIOHTTP2Errors.excessiveOutboundFrameBuffering(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.invalidALPNToken(),
NIOHTTP2Errors.invalidALPNToken(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.noSuchStream(streamID: .rootStream),
NIOHTTP2Errors.noSuchStream(streamID: .rootStream, file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.noSuchStream(streamID: 1),
NIOHTTP2Errors.noSuchStream(streamID: 2))
XCTAssertEqual(NIOHTTP2Errors.streamClosed(streamID: .rootStream, errorCode: .cancel),
NIOHTTP2Errors.streamClosed(streamID: .rootStream, errorCode: .cancel, file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.streamClosed(streamID: 1, errorCode: .cancel),
NIOHTTP2Errors.streamClosed(streamID: 1, errorCode: .compressionError))
XCTAssertNotEqual(NIOHTTP2Errors.streamClosed(streamID: 1, errorCode: .cancel),
NIOHTTP2Errors.streamClosed(streamID: 2, errorCode: .cancel))
XCTAssertEqual(NIOHTTP2Errors.badClientMagic(),
NIOHTTP2Errors.badClientMagic(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.badStreamStateTransition(),
NIOHTTP2Errors.badStreamStateTransition(file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.badStreamStateTransition(from: .closed),
NIOHTTP2Errors.badStreamStateTransition())
XCTAssertEqual(NIOHTTP2Errors.invalidFlowControlWindowSize(delta: 1, currentWindowSize: 2),
NIOHTTP2Errors.invalidFlowControlWindowSize(delta: 1, currentWindowSize: 2, file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.invalidFlowControlWindowSize(delta: 1, currentWindowSize: 2),
NIOHTTP2Errors.invalidFlowControlWindowSize(delta: 2, currentWindowSize: 2))
XCTAssertNotEqual(NIOHTTP2Errors.invalidFlowControlWindowSize(delta: 1, currentWindowSize: 3),
NIOHTTP2Errors.invalidFlowControlWindowSize(delta: 1, currentWindowSize: 2))
XCTAssertEqual(NIOHTTP2Errors.flowControlViolation(),
NIOHTTP2Errors.flowControlViolation(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.invalidSetting(setting: .init(parameter: .maxConcurrentStreams, value: 1)),
NIOHTTP2Errors.invalidSetting(setting: .init(parameter: .maxConcurrentStreams, value: 1), file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.invalidSetting(setting: .init(parameter: .maxConcurrentStreams, value: 1)),
NIOHTTP2Errors.invalidSetting(setting: .init(parameter: .maxConcurrentStreams, value: 2)))
XCTAssertEqual(NIOHTTP2Errors.ioOnClosedConnection(),
NIOHTTP2Errors.ioOnClosedConnection(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.receivedBadSettings(),
NIOHTTP2Errors.receivedBadSettings(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.maxStreamsViolation(),
NIOHTTP2Errors.maxStreamsViolation(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.streamIDTooSmall(),
NIOHTTP2Errors.streamIDTooSmall(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.missingPreface(),
NIOHTTP2Errors.missingPreface(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.createdStreamAfterGoaway(),
NIOHTTP2Errors.createdStreamAfterGoaway(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.invalidStreamIDForPeer(),
NIOHTTP2Errors.invalidStreamIDForPeer(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.raisedGoawayLastStreamID(),
NIOHTTP2Errors.raisedGoawayLastStreamID(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.invalidWindowIncrementSize(),
NIOHTTP2Errors.invalidWindowIncrementSize(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.pushInViolationOfSetting(),
NIOHTTP2Errors.pushInViolationOfSetting(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.unsupported(info: "info"),
NIOHTTP2Errors.unsupported(info: "info", file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.unsupported(info: "info"),
NIOHTTP2Errors.unsupported(info: "notinfo"))
XCTAssertEqual(NIOHTTP2Errors.unableToSerializeFrame(),
NIOHTTP2Errors.unableToSerializeFrame(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.unableToParseFrame(),
NIOHTTP2Errors.unableToParseFrame(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.missingPseudoHeader("missing"),
NIOHTTP2Errors.missingPseudoHeader("missing", file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.missingPseudoHeader("missing"),
NIOHTTP2Errors.missingPseudoHeader("notmissing"))
XCTAssertEqual(NIOHTTP2Errors.duplicatePseudoHeader("duplicate"),
NIOHTTP2Errors.duplicatePseudoHeader("duplicate", file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.duplicatePseudoHeader("duplicate"),
NIOHTTP2Errors.duplicatePseudoHeader("notduplicate"))
XCTAssertEqual(NIOHTTP2Errors.pseudoHeaderAfterRegularHeader("after"),
NIOHTTP2Errors.pseudoHeaderAfterRegularHeader("after", file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.pseudoHeaderAfterRegularHeader("after"),
NIOHTTP2Errors.pseudoHeaderAfterRegularHeader("notafter"))
XCTAssertEqual(NIOHTTP2Errors.unknownPseudoHeader("unknown"),
NIOHTTP2Errors.unknownPseudoHeader("unknown", file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.unknownPseudoHeader("unknown"),
NIOHTTP2Errors.unknownPseudoHeader("notunknown"))
XCTAssertEqual(NIOHTTP2Errors.invalidPseudoHeaders([:]),
NIOHTTP2Errors.invalidPseudoHeaders([:], file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.invalidPseudoHeaders([:]),
NIOHTTP2Errors.invalidPseudoHeaders(["not": "empty"]))
XCTAssertEqual(NIOHTTP2Errors.missingHostHeader(),
NIOHTTP2Errors.missingHostHeader(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.duplicateHostHeader(),
NIOHTTP2Errors.duplicateHostHeader(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.emptyPathHeader(),
NIOHTTP2Errors.emptyPathHeader(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.invalidStatusValue("invalid"),
NIOHTTP2Errors.invalidStatusValue("invalid", file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.invalidStatusValue("invalid"),
NIOHTTP2Errors.invalidStatusValue("notinvalid"))
XCTAssertEqual(NIOHTTP2Errors.priorityCycle(streamID: .rootStream),
NIOHTTP2Errors.priorityCycle(streamID: .rootStream, file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.priorityCycle(streamID: .rootStream),
NIOHTTP2Errors.priorityCycle(streamID: 1))
XCTAssertEqual(NIOHTTP2Errors.trailersWithoutEndStream(streamID: .rootStream),
NIOHTTP2Errors.trailersWithoutEndStream(streamID: .rootStream, file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.trailersWithoutEndStream(streamID: .rootStream),
NIOHTTP2Errors.trailersWithoutEndStream(streamID: 1))
XCTAssertEqual(NIOHTTP2Errors.invalidHTTP2HeaderFieldName("fieldName"),
NIOHTTP2Errors.invalidHTTP2HeaderFieldName("fieldName", file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.invalidHTTP2HeaderFieldName("fieldName"),
NIOHTTP2Errors.invalidHTTP2HeaderFieldName("notFieldName"))
XCTAssertEqual(NIOHTTP2Errors.forbiddenHeaderField(name: "name", value: "value"),
NIOHTTP2Errors.forbiddenHeaderField(name: "name", value: "value", file: "", line: 0))
XCTAssertNotEqual(NIOHTTP2Errors.forbiddenHeaderField(name: "name", value: "value"),
NIOHTTP2Errors.forbiddenHeaderField(name: "notname", value: "value"))
XCTAssertNotEqual(NIOHTTP2Errors.forbiddenHeaderField(name: "name", value: "value"),
NIOHTTP2Errors.forbiddenHeaderField(name: "name", value: "notvalue"))
XCTAssertEqual(NIOHTTP2Errors.contentLengthViolated(),
NIOHTTP2Errors.contentLengthViolated(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.excessiveEmptyDataFrames(),
NIOHTTP2Errors.excessiveEmptyDataFrames(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.excessivelyLargeHeaderBlock(),
NIOHTTP2Errors.excessivelyLargeHeaderBlock(file: "", line: 0))
XCTAssertEqual(NIOHTTP2Errors.noStreamIDAvailable(),
NIOHTTP2Errors.noStreamIDAvailable(file: "", line: 0))
}
func testFitsInAnExistentialContainer() {
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.ExcessiveOutboundFrameBuffering>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.InvalidALPNToken>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.NoSuchStream>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.StreamClosed>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.BadClientMagic>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.BadStreamStateTransition>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.InvalidFlowControlWindowSize>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.FlowControlViolation>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.InvalidSetting>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.IOOnClosedConnection>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.ReceivedBadSettings>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.MaxStreamsViolation>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.StreamIDTooSmall>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.MissingPreface>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.CreatedStreamAfterGoaway>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.InvalidStreamIDForPeer>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.RaisedGoawayLastStreamID>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.InvalidWindowIncrementSize>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.PushInViolationOfSetting>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.Unsupported>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.UnableToSerializeFrame>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.UnableToParseFrame>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.MissingPseudoHeader>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.DuplicatePseudoHeader>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.PseudoHeaderAfterRegularHeader>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.UnknownPseudoHeader>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.InvalidPseudoHeaders>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.MissingHostHeader>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.DuplicateHostHeader>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.EmptyPathHeader>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.InvalidStatusValue>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.PriorityCycle>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.TrailersWithoutEndStream>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.InvalidHTTP2HeaderFieldName>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.ForbiddenHeaderField>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.ContentLengthViolated>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.ExcessiveEmptyDataFrames>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.ExcessivelyLargeHeaderBlock>.size, 24)
XCTAssertLessThanOrEqual(MemoryLayout<NIOHTTP2Errors.NoStreamIDAvailable>.size, 24)
}
}
@@ -167,7 +167,7 @@ final class HTTP2FramePayloadStreamMultiplexerTests: XCTestCase {
// At this stage the stream should be closed with the appropriate error code.
XCTAssertEqual(closeError as? NIOHTTP2Errors.StreamClosed,
NIOHTTP2Errors.StreamClosed(streamID: streamID, errorCode: .cancel))
NIOHTTP2Errors.streamClosed(streamID: streamID, errorCode: .cancel))
XCTAssertNoThrow(try self.channel.finish())
}
@@ -204,7 +204,7 @@ final class HTTP2FramePayloadStreamMultiplexerTests: XCTestCase {
// At this stage the stream should be closed with the appropriate manufactured error code.
XCTAssertEqual(closeError as? NIOHTTP2Errors.StreamClosed,
NIOHTTP2Errors.StreamClosed(streamID: streamID, errorCode: .refusedStream))
NIOHTTP2Errors.streamClosed(streamID: streamID, errorCode: .refusedStream))
XCTAssertNoThrow(try self.channel.finish())
}
@@ -433,7 +433,7 @@ final class HTTP2FramePayloadStreamMultiplexerTests: XCTestCase {
// Now send the stream closed event. This will fail the close promise.
let userEvent = StreamClosedEvent(streamID: streamID, reason: .cancel)
self.channel.pipeline.fireUserInboundEventTriggered(userEvent)
XCTAssertEqual(closeError as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.StreamClosed(streamID: streamID, errorCode: .cancel))
XCTAssertEqual(closeError as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.streamClosed(streamID: streamID, errorCode: .cancel))
XCTAssertNoThrow(try self.channel.finish())
}
@@ -655,7 +655,7 @@ final class HTTP2FramePayloadStreamMultiplexerTests: XCTestCase {
// Now we're going to deliver a normal close to the stream.
let userEvent = StreamClosedEvent(streamID: streamID, reason: .cancel)
self.channel.pipeline.fireUserInboundEventTriggered(userEvent)
XCTAssertEqual(writeError as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.StreamClosed(streamID: streamID, errorCode: .cancel))
XCTAssertEqual(writeError as? NIOHTTP2Errors.StreamClosed, NIOHTTP2Errors.streamClosed(streamID: streamID, errorCode: .cancel))
XCTAssertNoThrow(try self.channel.finish())
}
@@ -385,7 +385,7 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic request.
let requestHeaders = HPACKHeaders([(":path", "/post"), (":scheme", "https"), (":authority", "example.org"), ("other", "header")])
XCTAssertThrowsError(try self.channel.writeInbound(HTTP2Frame.FramePayload.headers(.init(headers: requestHeaders)))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.MissingPseudoHeader, NIOHTTP2Errors.MissingPseudoHeader(":method"))
XCTAssertEqual(error as? NIOHTTP2Errors.MissingPseudoHeader, NIOHTTP2Errors.missingPseudoHeader(":method"))
}
// We already know there's an error here.
@@ -398,7 +398,7 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic request.
let requestHeaders = HPACKHeaders([(":path", "/post"), (":method", "GET"), (":method", "GET"), (":scheme", "https"), (":authority", "example.org"), ("other", "header")])
XCTAssertThrowsError(try self.channel.writeInbound(HTTP2Frame.FramePayload.headers(.init(headers: requestHeaders)))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicatePseudoHeader, NIOHTTP2Errors.DuplicatePseudoHeader(":method"))
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicatePseudoHeader, NIOHTTP2Errors.duplicatePseudoHeader(":method"))
}
// We already know there's an error here.
@@ -411,7 +411,7 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic request.
let requestHeaders = HPACKHeaders([(":method", "GET"), (":scheme", "https"), (":authority", "example.org"), ("other", "header")])
XCTAssertThrowsError(try self.channel.writeInbound(HTTP2Frame.FramePayload.headers(.init(headers: requestHeaders)))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.MissingPseudoHeader, NIOHTTP2Errors.MissingPseudoHeader(":path"))
XCTAssertEqual(error as? NIOHTTP2Errors.MissingPseudoHeader, NIOHTTP2Errors.missingPseudoHeader(":path"))
}
// We already know there's an error here.
@@ -424,7 +424,7 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic request.
let requestHeaders = HPACKHeaders([(":path", "/post"), (":path", "/post"), (":method", "GET"), (":scheme", "https"), (":authority", "example.org"), ("other", "header")])
XCTAssertThrowsError(try self.channel.writeInbound(HTTP2Frame.FramePayload.headers(.init(headers: requestHeaders)))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicatePseudoHeader, NIOHTTP2Errors.DuplicatePseudoHeader(":path"))
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicatePseudoHeader, NIOHTTP2Errors.duplicatePseudoHeader(":path"))
}
// We already know there's an error here.
@@ -437,7 +437,7 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic request.
let requestHeaders = HPACKHeaders([(":method", "GET"), (":scheme", "https"), (":path", "/post"), ("other", "header")])
XCTAssertThrowsError(try self.channel.writeInbound(HTTP2Frame.FramePayload.headers(.init(headers: requestHeaders)))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.MissingPseudoHeader, NIOHTTP2Errors.MissingPseudoHeader(":authority"))
XCTAssertEqual(error as? NIOHTTP2Errors.MissingPseudoHeader, NIOHTTP2Errors.missingPseudoHeader(":authority"))
}
// We already know there's an error here.
@@ -450,7 +450,7 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic request.
let requestHeaders = HPACKHeaders([(":path", "/post"), (":method", "GET"), (":scheme", "https"), (":authority", "example.org"), (":authority", "example.org"), ("other", "header")])
XCTAssertThrowsError(try self.channel.writeInbound(HTTP2Frame.FramePayload.headers(.init(headers: requestHeaders)))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicatePseudoHeader, NIOHTTP2Errors.DuplicatePseudoHeader(":authority"))
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicatePseudoHeader, NIOHTTP2Errors.duplicatePseudoHeader(":authority"))
}
// We already know there's an error here.
@@ -463,7 +463,7 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic request.
let requestHeaders = HPACKHeaders([(":method", "GET"), (":authority", "example.org"), (":path", "/post"), ("other", "header")])
XCTAssertThrowsError(try self.channel.writeInbound(HTTP2Frame.FramePayload.headers(.init(headers: requestHeaders)))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.MissingPseudoHeader, NIOHTTP2Errors.MissingPseudoHeader(":scheme"))
XCTAssertEqual(error as? NIOHTTP2Errors.MissingPseudoHeader, NIOHTTP2Errors.missingPseudoHeader(":scheme"))
}
// We already know there's an error here.
@@ -476,7 +476,7 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic request.
let requestHeaders = HPACKHeaders([(":path", "/post"), (":method", "GET"), (":scheme", "https"), (":scheme", "https"), (":authority", "example.org"), ("other", "header")])
XCTAssertThrowsError(try self.channel.writeInbound(HTTP2Frame.FramePayload.headers(.init(headers: requestHeaders)))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicatePseudoHeader, NIOHTTP2Errors.DuplicatePseudoHeader(":scheme"))
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicatePseudoHeader, NIOHTTP2Errors.duplicatePseudoHeader(":scheme"))
}
// We already know there's an error here.
@@ -489,7 +489,7 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic response.
let requestHeaders = HPACKHeaders([("other", "header")])
XCTAssertThrowsError(try self.channel.writeInbound(HTTP2Frame.FramePayload.headers(.init(headers: requestHeaders)))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.MissingPseudoHeader, NIOHTTP2Errors.MissingPseudoHeader(":status"))
XCTAssertEqual(error as? NIOHTTP2Errors.MissingPseudoHeader, NIOHTTP2Errors.missingPseudoHeader(":status"))
}
// We already know there's an error here.
@@ -502,7 +502,7 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic request.
let requestHeaders = HPACKHeaders([(":status", "200"), (":status", "404"), ("other", "header")])
XCTAssertThrowsError(try self.channel.writeInbound(HTTP2Frame.FramePayload.headers(.init(headers: requestHeaders)))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicatePseudoHeader, NIOHTTP2Errors.DuplicatePseudoHeader(":status"))
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicatePseudoHeader, NIOHTTP2Errors.duplicatePseudoHeader(":status"))
}
// We already know there's an error here.
@@ -515,7 +515,7 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic response.
let requestHeaders = HPACKHeaders([(":status", "captivating")])
XCTAssertThrowsError(try self.channel.writeInbound(HTTP2Frame.FramePayload.headers(.init(headers: requestHeaders)))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.InvalidStatusValue, NIOHTTP2Errors.InvalidStatusValue("captivating"))
XCTAssertEqual(error as? NIOHTTP2Errors.InvalidStatusValue, NIOHTTP2Errors.invalidStatusValue("captivating"))
}
// We already know there's an error here.
@@ -528,12 +528,12 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
// A basic request without Host.
let request = HTTPClientRequestPart.head(.init(version: .init(major: 1, minor: 1), method: .GET, uri: "/"))
XCTAssertThrowsError(try self.channel.writeOutbound(request)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.MissingHostHeader, NIOHTTP2Errors.MissingHostHeader())
XCTAssertEqual(error as? NIOHTTP2Errors.MissingHostHeader, NIOHTTP2Errors.missingHostHeader())
}
// We check the channel for an error as the above only checks the promise.
XCTAssertThrowsError(try self.channel.finish()) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.MissingHostHeader, NIOHTTP2Errors.MissingHostHeader())
XCTAssertEqual(error as? NIOHTTP2Errors.MissingHostHeader, NIOHTTP2Errors.missingHostHeader())
}
}
@@ -546,12 +546,12 @@ final class HTTP2FramePayloadToHTTP1CodecTests: XCTestCase {
requestHead.headers.add(name: "Host", value: "cat")
let request = HTTPClientRequestPart.head(requestHead)
XCTAssertThrowsError(try self.channel.writeOutbound(request)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicateHostHeader, NIOHTTP2Errors.DuplicateHostHeader())
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicateHostHeader, NIOHTTP2Errors.duplicateHostHeader())
}
// We check the channel for an error as the above only checks the promise.
XCTAssertThrowsError(try self.channel.finish()) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicateHostHeader, NIOHTTP2Errors.DuplicateHostHeader())
XCTAssertEqual(error as? NIOHTTP2Errors.DuplicateHostHeader, NIOHTTP2Errors.duplicateHostHeader())
}
}
@@ -243,7 +243,7 @@ class OutboundFlowControlBufferTests: XCTestCase {
return
}
for (_, promise) in droppedFrames {
promise?.fail(NIOHTTP2Errors.StreamClosed(streamID: streamOne, errorCode: .protocolError))
promise?.fail(NIOHTTP2Errors.streamClosed(streamID: streamOne, errorCode: .protocolError))
}
XCTAssertThrowsError(try dataPromise.futureResult.wait()) {
@@ -374,10 +374,10 @@ class OutboundFlowControlBufferTests: XCTestCase {
func testRejectsPrioritySelfDependency() {
XCTAssertThrowsError(try self.buffer.priorityUpdate(streamID: 1, priorityData: .init(exclusive: false, dependency: 1, weight: 36))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.PriorityCycle(streamID: 1))
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.priorityCycle(streamID: 1))
}
XCTAssertThrowsError(try self.buffer.priorityUpdate(streamID: 1, priorityData: .init(exclusive: true, dependency: 1, weight: 36))) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.PriorityCycle(streamID: 1))
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.priorityCycle(streamID: 1))
}
}
}
@@ -1001,7 +1001,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
self.interactInMemory(self.clientChannel, self.serverChannel)
XCTAssertNoThrow(try XCTAssertEqual(NIOHTTP2Errors.BadClientMagic(),
XCTAssertNoThrow(try XCTAssertEqual(NIOHTTP2Errors.badClientMagic(),
errorSeenPromise.futureResult.wait() as? NIOHTTP2Errors.BadClientMagic))
// The client will get two frames: a SETTINGS frame, and a GOAWAY frame. We don't want to decode these, so we
@@ -1201,7 +1201,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
return
}
XCTAssertThrowsError(try self.serverChannel.writeInbound(frameData)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.PriorityCycle(streamID: 1))
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.priorityCycle(streamID: 1))
}
guard let responseFrame = try assertNoThrowWithValue(self.serverChannel.readOutbound(as: ByteBuffer.self)) else {
@@ -1233,7 +1233,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
return
}
XCTAssertThrowsError(try self.serverChannel.writeInbound(frameData)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.PriorityCycle(streamID: 1))
XCTAssertEqual(error as? NIOHTTP2Errors.PriorityCycle, NIOHTTP2Errors.priorityCycle(streamID: 1))
}
guard let responseFrame = try assertNoThrowWithValue(self.serverChannel.readOutbound(as: ByteBuffer.self)) else {
@@ -1264,7 +1264,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
return
}
XCTAssertThrowsError(try self.serverChannel.writeInbound(frameData)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.InvalidHTTP2HeaderFieldName, NIOHTTP2Errors.InvalidHTTP2HeaderFieldName("UPPERCASE"))
XCTAssertEqual(error as? NIOHTTP2Errors.InvalidHTTP2HeaderFieldName, NIOHTTP2Errors.invalidHTTP2HeaderFieldName("UPPERCASE"))
}
guard let responseFrame = try assertNoThrowWithValue(self.serverChannel.readOutbound(as: ByteBuffer.self)) else {
@@ -1296,7 +1296,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
settingsBuffer.writeBytes(weirdSettingsFrame)
XCTAssertThrowsError(try self.clientChannel.writeInbound(settingsBuffer)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.InvalidSetting, NIOHTTP2Errors.InvalidSetting(setting: HTTP2Setting(parameter: .enablePush, value: 3)))
XCTAssertEqual(error as? NIOHTTP2Errors.InvalidSetting, NIOHTTP2Errors.invalidSetting(setting: HTTP2Setting(parameter: .enablePush, value: 3)))
}
guard let goAwayFrame = try assertNoThrowWithValue(self.clientChannel.readOutbound(as: ByteBuffer.self)) else {
@@ -1453,7 +1453,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
// The server should have errored.
XCTAssertThrowsError(try self.serverChannel.writeInbound(bytes)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessiveEmptyDataFrames, NIOHTTP2Errors.ExcessiveEmptyDataFrames())
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessiveEmptyDataFrames, NIOHTTP2Errors.excessiveEmptyDataFrames())
}
guard let serverBytes = try assertNoThrowWithValue(self.serverChannel.readOutbound(as: ByteBuffer.self)) else {
@@ -1505,7 +1505,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
// The server should have errored.
XCTAssertThrowsError(try self.serverChannel.writeInbound(bytes)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessiveEmptyDataFrames, NIOHTTP2Errors.ExcessiveEmptyDataFrames())
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessiveEmptyDataFrames, NIOHTTP2Errors.excessiveEmptyDataFrames())
}
guard let serverBytes = try assertNoThrowWithValue(self.serverChannel.readOutbound(as: ByteBuffer.self)) else {
@@ -1546,7 +1546,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
return
}
XCTAssertThrowsError(try self.serverChannel.writeInbound(pingBytes)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessiveOutboundFrameBuffering, NIOHTTP2Errors.ExcessiveOutboundFrameBuffering())
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessiveOutboundFrameBuffering, NIOHTTP2Errors.excessiveOutboundFrameBuffering())
}
XCTAssertNoThrow(try self.clientChannel.finish())
@@ -1573,7 +1573,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
return
}
XCTAssertThrowsError(try self.serverChannel.writeInbound(settingsBytes)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessiveOutboundFrameBuffering, NIOHTTP2Errors.ExcessiveOutboundFrameBuffering())
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessiveOutboundFrameBuffering, NIOHTTP2Errors.excessiveOutboundFrameBuffering())
}
XCTAssertNoThrow(try self.clientChannel.finish())
@@ -1677,7 +1677,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
return
}
XCTAssertThrowsError(try self.serverChannel.writeInbound(frameData)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.UnableToParseFrame, NIOHTTP2Errors.UnableToParseFrame())
XCTAssertEqual(error as? NIOHTTP2Errors.UnableToParseFrame, NIOHTTP2Errors.unableToParseFrame())
}
guard let responseFrame = try assertNoThrowWithValue(self.serverChannel.readOutbound(as: ByteBuffer.self)) else {
@@ -1728,7 +1728,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
// But if we send one more frame, that will be treated as a violation of SETTINGS_MAX_HEADER_LIST_SIZE.
XCTAssertThrowsError(try self.serverChannel.writeInbound(firstBuffer.getSlice(at: firstBuffer.writerIndex - 10, length: 10)!)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessivelyLargeHeaderBlock, NIOHTTP2Errors.ExcessivelyLargeHeaderBlock())
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessivelyLargeHeaderBlock, NIOHTTP2Errors.excessivelyLargeHeaderBlock())
}
guard let responseFrame = try assertNoThrowWithValue(self.serverChannel.readOutbound(as: ByteBuffer.self)) else {
XCTFail("Did not receive response frame")
@@ -1763,7 +1763,7 @@ class SimpleClientServerFramePayloadStreamTests: XCTestCase {
// This frame will be treated as a violation of SETTINGS_MAX_HEADER_LIST_SIZE.
XCTAssertThrowsError(try self.serverChannel.writeInbound(buffer)) { error in
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessivelyLargeHeaderBlock, NIOHTTP2Errors.ExcessivelyLargeHeaderBlock())
XCTAssertEqual(error as? NIOHTTP2Errors.ExcessivelyLargeHeaderBlock, NIOHTTP2Errors.excessivelyLargeHeaderBlock())
}
guard let responseFrame = try assertNoThrowWithValue(self.serverChannel.readOutbound(as: ByteBuffer.self)) else {
XCTFail("Did not receive response frame")