HTTPHeaders
public struct HTTPHeaders
extension HTTPHeaders: ExpressibleByDictionaryLiteral
Defines storage for a collection of HTTPHeaders for use in a URLRequest.
An instance can be initialized using a dictionary literal
(e.g. headers = [.contentType: HTTPMediaType.json.stringValue()]).
-
A
Dictionaryrepresentation of all contained header fields within the receiver.Declaration
Swift
public var allHTTPHeaderFields: [String : String] { get } -
Replace the current value for a given
HTTPHeaderwith 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
headerThe
HTTPHeaderwhose corresponding value should be replaced or set.valueThe
Stringvalue 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
headerThe
HTTPHeaderto 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
headerThe
HTTPHeaderto inspect.Return Value
The
Stringvalue for the corresponding header (if it was present).
-
Initializes a
HTTPHeadersbased on aDictionaryliteral.Declaration
Swift
public init(dictionaryLiteral elements: (HTTPHeader, String)...)Parameters
elementsA
Dictionaryliteral (e.g.[.contentType: "application/json"]).
View on GitHub
Install in Dash
HTTPHeaders Structure Reference