HTTPHeaders

public struct HTTPHeaders : CustomStringConvertible, ExpressibleByDictionaryLiteral

A representation of a block of HTTP header fields.

HTTP header fields are a complex data structure. The most natural representation for these is a sequence of two-tuples of field name and field value, both as strings. This structure preserves that representation, but provides a number of convenience features in addition to it.

For example, this structure enables access to header fields based on the case-insensitive form of the field name, but preserves the original case of the field when needed. It also supports recomposing headers to a maximally joined or split representation, such that header fields that are able to be repeated can be represented appropriately.

  • Declaration

    Swift

    public var description: String { get }
  • Construct a HTTPHeaders structure.

    Declaration

    Swift

    public init(_ headers: [(String, String)] = [])
  • Construct a HTTPHeaders structure.

    Declaration

    Swift

    public init(dictionaryLiteral elements: (String, String)...)
  • Declaration

    Swift

    public mutating func add(name: String, value: String)

    Parameters

    value

    The header field value to add for the given name.

  • Declaration

    Swift

    public mutating func replaceOrAdd(name: String, value: String)

    Parameters

    value

    The header field value to add for the given name.

  • Remove all values for a given header name from the block.

    This method uses case-insensitive comparisons for the header field name.

    Declaration

    Swift

    public mutating func remove(name nameToRemove: String)

    Parameters

    name

    The name of the header field to remove from the block.

  • Retrieve all of the values for a give header field name from the block.

    This method uses case-insensitive comparisons for the header field name. It does not return a maximally-decomposed list of the header fields, but instead returns them in their original representation: that means that a comma-separated header field list may contain more than one entry, some of which contain commas and some do not. If you want a representation of the header fields suitable for performing computation on, consider getCanonicalForm.

    Declaration

    Swift

    public subscript(name: String) -> [String] { get }

    Parameters

    name

    The header field name whose values are to be retrieved.

    Return Value

    A list of the values for that header field name.

  • Undocumented

    Declaration

    Swift

    public func contains(name: String) -> Bool
  • Retrieves the header values for the given header field in canonical form: that is, splitting them on commas as extensively as possible such that multiple values received on the one line are returned as separate entries. Also respects the fact that Set-Cookie should not be split in this way.

    Declaration

    Swift

    public subscript(canonicalForm name: String) -> [Substring] { get }

    Parameters

    name

    The header field name whose values are to be retrieved.

    Return Value

    A list of the values for that header field name.

  • Declaration

    Swift

    public static func == (lhs: HTTPHeaders, rhs: HTTPHeaders) -> Bool