mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-24 04:37:50 +00:00
Motivation: In general we should try to be specific about what we're referring to. "Structured headers" is not really an accurate description of what this module works with: "Structured Header Field Values", or "Structured Field Value" is usually better. To that end this change adjusts our naming to be closer to what we want. It also changes our module names to prioritise the use of the Codable-based one. Modifications: - Renamed CodableStructuredHeaders to StructuredFieldValues. - Renamed StructuredHeaders to RawStructuredFieldValues. - Renamed a number of types from Field to FieldValue. - Renamed a number of types from Header to Field or FieldValue. - Renamed some functions along the above lines. Result: Better and more consistent terminology will be used.
69 lines
2.6 KiB
Swift
69 lines
2.6 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MARK: - StructuredHeaderError
|
|
|
|
/// Errors that may be encountered when working with structured headers.
|
|
public struct StructuredHeaderError: Error {
|
|
private enum _BaseError: Hashable {
|
|
case invalidTrailingBytes
|
|
case invalidInnerList
|
|
case invalidItem
|
|
case invalidKey
|
|
case invalidIntegerOrDecimal
|
|
case invalidString
|
|
case invalidByteSequence
|
|
case invalidBoolean
|
|
case invalidToken
|
|
case invalidList
|
|
case invalidDictionary
|
|
case missingKey
|
|
case invalidTypeForItem
|
|
case integerOutOfRange
|
|
case indexOutOfRange
|
|
}
|
|
|
|
private var base: _BaseError
|
|
|
|
private init(_ base: _BaseError) {
|
|
self.base = base
|
|
}
|
|
}
|
|
|
|
extension StructuredHeaderError {
|
|
public static let invalidTrailingBytes = StructuredHeaderError(.invalidTrailingBytes)
|
|
public static let invalidInnerList = StructuredHeaderError(.invalidInnerList)
|
|
public static let invalidItem = StructuredHeaderError(.invalidItem)
|
|
public static let invalidKey = StructuredHeaderError(.invalidKey)
|
|
public static let invalidIntegerOrDecimal = StructuredHeaderError(.invalidIntegerOrDecimal)
|
|
public static let invalidString = StructuredHeaderError(.invalidString)
|
|
public static let invalidByteSequence = StructuredHeaderError(.invalidByteSequence)
|
|
public static let invalidBoolean = StructuredHeaderError(.invalidBoolean)
|
|
public static let invalidToken = StructuredHeaderError(.invalidToken)
|
|
public static let invalidList = StructuredHeaderError(.invalidList)
|
|
public static let invalidDictionary = StructuredHeaderError(.invalidDictionary)
|
|
public static let missingKey = StructuredHeaderError(.missingKey)
|
|
public static let invalidTypeForItem = StructuredHeaderError(.invalidTypeForItem)
|
|
public static let integerOutOfRange = StructuredHeaderError(.integerOutOfRange)
|
|
public static let indexOutOfRange = StructuredHeaderError(.indexOutOfRange)
|
|
}
|
|
|
|
extension StructuredHeaderError: Hashable {}
|
|
|
|
extension StructuredHeaderError: CustomStringConvertible {
|
|
public var description: String {
|
|
String(describing: self.base)
|
|
}
|
|
}
|