HTTPHeaders
public struct HTTPHeaders
extension HTTPHeaders: ExpressibleByDictionaryLiteral
Defines storage for a collection of HTTPHeader
s for use in a URLRequest
.
An instance can be initialized using a dictionary literal
(e.g. headers = [.contentType: HTTPMediaType.json.stringValue()]
).
-
A
Dictionary
representation of all contained header fields within the receiver.Declaration
Swift
public var allHTTPHeaderFields: [String : String] { get }
-
Replace the current value for a given
HTTPHeader
with a new value (or adds it to the receiver if a header with the same name was not already present).Declaration
Swift
public mutating func replaceOrAdd(header: HTTPHeader, value: String)
Parameters
header
The
HTTPHeader
whose corresponding value should be replaced or set.value
The
String
value to associated with a given header. -
Remove a
HTTPHeader
(and its corresponding value) if it exists in the receiver. (This method has no effect if no header with a given name exists in the receiver).Declaration
Swift
public mutating func remove(header: HTTPHeader)
Parameters
header
The
HTTPHeader
to remove from the receiver. -
Retrieves the value for a given
HTTPHeader
(if it is present in the receiver).Declaration
Swift
public func value(for header: HTTPHeader) -> String?
Parameters
header
The
HTTPHeader
to inspect.Return Value
The
String
value for the corresponding header (if it was present).
-
Initializes a
HTTPHeaders
based on aDictionary
literal.Declaration
Swift
public init(dictionaryLiteral elements: (HTTPHeader, String)...)
Parameters
elements
A
Dictionary
literal (e.g.[.contentType: "application/json"]
).