mirror of
https://github.com/apple/swift-http-structured-headers
synced 2026-11-24 04:37:50 +00:00
Motivation: We had a proliferation of decode/encode methods that required users to tell us how to encode their structured header field. This is a bit annoying for two reasons: firstly, it requires users to encode this piece of information separately from their header field; secondly, it makes it very hard to offer a generic interface to load something as a structured header field! Modifications: - Add a new StructuredHeaderField protocol that refines Codable and expresses what type of header field is used. - Remove the fancy encode/decode methods. Result: Simpler interfaces.
36 lines
1.2 KiB
Swift
36 lines
1.2 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// A `StructuredHeaderField` is a `Codable` representation of a HTTP Structured
|
|
/// Header Field.
|
|
///
|
|
/// This protocol is a helper protocol that refines `Codable` to indicate what kind
|
|
/// of header field a given field uses.
|
|
public protocol StructuredHeaderField: Codable {
|
|
static var structuredFieldType: StructuredHeaderFieldType { get }
|
|
}
|
|
|
|
|
|
/// The kinds of header fields used in HTTP Structured Headers.
|
|
public enum StructuredHeaderFieldType {
|
|
/// An item field consists of a single item, optionally with parameters.
|
|
case item
|
|
|
|
/// A list field consists of a list made up of inner lists or items.
|
|
case list
|
|
|
|
/// A dictionary field is an ordered collection of key-value pairs.
|
|
case dictionary
|
|
}
|