HTTPHeaders
public struct HTTPHeaders : CustomStringConvertible, ExpressibleByDictionaryLiteral
extension HTTPHeaders: RandomAccessCollection
extension HTTPHeaders: Equatable
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)...)
-
Add a header name/value pair to the block.
This method is strictly additive: if there are other values for the given header name already in the block, this will add a new entry.
Declaration
Swift
public mutating func add(name: String, value: String)
Parameters
name
The header field name. For maximum compatibility this should be an ASCII string. For future-proofing with HTTP/2 lowercase header names are strongly recommended.
value
The header field value to add for the given name.
-
Add a sequence of header name/value pairs to the block.
This method is strictly additive: if there are other entries with the same header name already in the block, this will add new entries.
Declaration
Swift
@inlinable public mutating func add<S>(contentsOf other: S) where S : Sequence, S.Element == (String, String)
Parameters
contentsOf
The sequence of header name/value pairs. For maximum compatibility the header should be an ASCII string. For future-proofing with HTTP/2 lowercase header names are strongly recommended.
-
Add another block of headers to the block.
Declaration
Swift
public mutating func add(contentsOf other: HTTPHeaders)
Parameters
contentsOf
The block of headers to add to these headers.
-
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
subscript(canonicalForm:)
.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.
-
Retrieves the first value for a given header field name from the block.
This method uses case-insensitive comparisons for the header field name. It does not return the first value from a maximally-decomposed list of the header fields, but instead returns the first value from the 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
subscript(canonicalForm:)
.Declaration
Swift
public func first(name: String) -> String?
Parameters
name
The header field name whose first value should be retrieved.
Return Value
The first value for the 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.
-
The total number of headers that can be contained without allocating new storage.
Declaration
Swift
public var capacity: Int { get }
-
Reserves enough space to store the specified number of headers.
Declaration
Swift
public mutating func reserveCapacity(_ minimumCapacity: Int)
Parameters
minimumCapacity
The requested number of headers to store.
-
Declaration
Swift
public typealias Element = (name: String, value: String)
-
Declaration
Swift
public struct Index : Comparable
-
Declaration
Swift
public var startIndex: HTTPHeaders.Index { get }
-
Declaration
Swift
public var endIndex: HTTPHeaders.Index { get }
-
-
-
-
Declaration
Swift
public static func == (lhs: HTTPHeaders, rhs: HTTPHeaders) -> Bool