Files
swift-nio-http2/Sources/NIOHTTP2/HTTP2Error.swift
T
Cory Benfield c2c39c63f6 Basic PRIORITY frame validation. (#71)
Motivation:

In the future we'll want to use PRIORITY frames to provide feedback on
how we emit data. Additionally, RFC 7540 forbids certain kinds of
PRIORITY frame, which right now we tolerate receiving. We can design a
minor PRIORITY shim to ensure that we have a code path for PRIORITY data
to be passed around, and then use this shim to enforce RFC 7540's
requirements.

Modifications:

- Added support for PRIORITY frame data inbound.
- Enforce that frames may not establish self-dependency.

Result:

Better policing of RFC 7540 constraints.
2019-03-25 18:09:46 +00:00

217 lines
6.5 KiB
Swift

//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
public protocol NIOHTTP2Error: Equatable, Error { }
/// Errors that NIO raises when handling HTTP/2 connections.
public enum NIOHTTP2Errors {
/// NIO's upgrade handler encountered a successful upgrade to a protocol that it
/// does not recognise.
public struct InvalidALPNToken: NIOHTTP2Error {
public init() { }
}
/// An attempt was made to issue a write on a stream that does not exist.
public struct NoSuchStream: NIOHTTP2Error {
/// The stream ID that was used that does not exist.
public var streamID: HTTP2StreamID
public init(streamID: HTTP2StreamID) {
self.streamID = streamID
}
}
/// A stream was closed.
public struct StreamClosed: NIOHTTP2Error {
/// The stream ID that was closed.
public var streamID: HTTP2StreamID
/// The error code associated with the closure.
public var errorCode: HTTP2ErrorCode
public init(streamID: HTTP2StreamID, errorCode: HTTP2ErrorCode) {
self.streamID = streamID
self.errorCode = errorCode
}
}
public struct BadClientMagic: NIOHTTP2Error {
public init() {}
}
/// A stream state transition was attempted that was not valid.
public struct BadStreamStateTransition: NIOHTTP2Error {
public init() { }
}
/// An attempt was made to change the flow control window size, either via
/// SETTINGS or WINDOW_UPDATE, but this change would move the flow control
/// window size out of bounds.
public struct InvalidFlowControlWindowSize: NIOHTTP2Error {
/// The delta being applied to the flow control window.
public var delta: Int
/// The size of the flow control window before the delta was applied.
public var currentWindowSize: Int
public init(delta: Int, currentWindowSize: Int) {
self.delta = delta
self.currentWindowSize = currentWindowSize
}
}
/// A frame was sent or received that violates HTTP/2 flow control rules.
public struct FlowControlViolation: NIOHTTP2Error {
public init() { }
}
/// A SETTINGS frame was sent or received with an invalid setting.
public struct InvalidSetting: NIOHTTP2Error {
/// The invalid setting.
public var setting: HTTP2Setting
public init(setting: HTTP2Setting) {
self.setting = setting
}
}
/// An attempt to perform I/O was made on a connection that is already closed.
public struct IOOnClosedConnection: NIOHTTP2Error {
public init() { }
}
/// A SETTINGS frame was received that is invalid.
public struct ReceivedBadSettings: NIOHTTP2Error {
public init() { }
}
/// A violation of SETTINGS_MAX_CONCURRENT_STREAMS occurred.
public struct MaxStreamsViolation: NIOHTTP2Error {
public init() { }
}
/// An attempt was made to use a stream ID that is too small.
public struct StreamIDTooSmall: NIOHTTP2Error {
public init() { }
}
/// An attempt was made to send a frame without having previously sent a connection preface!
public struct MissingPreface: NIOHTTP2Error {
public init() { }
}
/// An attempt was made to create a stream after a GOAWAY frame has forbidden further
/// stream creation.
public struct CreatedStreamAfterGoaway: NIOHTTP2Error {
public init() { }
}
/// A peer has attempted to create a stream with a stream ID it is not permitted to use.
public struct InvalidStreamIDForPeer: NIOHTTP2Error {
public init() { }
}
/// An attempt was made to send a new GOAWAY frame whose lastStreamID is higher than the previous value.
public struct RaisedGoawayLastStreamID: NIOHTTP2Error {
public init() { }
}
/// The size of the window increment is invalid.
public struct InvalidWindowIncrementSize: NIOHTTP2Error {
public init() { }
}
/// An attempt was made to push a stream, even though the settings forbid it.
public struct PushInViolationOfSetting: NIOHTTP2Error {
public init() { }
}
/// An attempt was made to use a currently unsupported feature.
public struct Unsupported: NIOHTTP2Error {
public var info: String
public init(info: String) {
self.info = info
}
}
public struct UnableToSerializeFrame: NIOHTTP2Error {
public init() { }
}
public struct UnableToParseFrame: NIOHTTP2Error {
public init() { }
}
/// A pseudo-header field is missing.
public struct MissingPseudoHeader: NIOHTTP2Error {
public var name: String
public init(_ name: String) {
self.name = name
}
}
/// A pseudo-header field has been duplicated.
public struct DuplicatePseudoHeader: NIOHTTP2Error {
public var name: String
public init(_ name: String) {
self.name = name
}
}
/// An outbound request was about to be sent, but does not contain a Host header.
public struct MissingHostHeader: NIOHTTP2Error {
public init() { }
}
/// An outbound request was about to be sent, but it contains a duplicated Host header.
public struct DuplicateHostHeader: NIOHTTP2Error {
public init() { }
}
/// A :status header was received with an invalid value.
public struct InvalidStatusValue: NIOHTTP2Error {
public var value: String
public init(_ value: String) {
self.value = value
}
}
/// A priority update was received that would create a PRIORITY cycle.
public struct PriorityCycle: NIOHTTP2Error {
/// The affected stream ID.
public var streamID: HTTP2StreamID
public init(streamID: HTTP2StreamID) {
self.streamID = streamID
}
}
}
/// This enum covers errors that are thrown internally for messaging reasons. These should
/// not leak.
internal enum InternalError: Error {
case attemptedToCreateStream
case codecError(code: HTTP2ErrorCode)
}
extension InternalError: Hashable { }