RestingHeaderProvider
public class RestingHeaderProvider : HeaderProvider
A default implementation of HeaderProvider
supporting dynamic header provisioning.
-
The headers to add to a request on a given time. Generated from
providers
, discartingnil
values.Declaration
Swift
public var headers: [String : String] { get }
-
Creates a new
RestingHeaderProvider
with the given header callbacks.Declaration
Swift
public init(providers: [String : () -> (String?)] = [:])
Parameters
providers
The callbacks to generate headers for requests. Keys indicate the name and the return of the callback the value of the header to add.
nil
values are discarted. -
Adds a static header value for the given key.
Adding a header to an existing overrides the previous one.
Declaration
Swift
public func addHeader(key: String, value: String)
Parameters
key
The name of the header.
value
The value of the header.
-
Adds a dynamic header value for the given key.
Adding a header to an existing overrides the previous one.
Declaration
Swift
public func addHeader(key: String, provider: @escaping () -> String?)
Parameters
key
The name of the header.
provider
The provider to call for the header value.
nil
values are discarted. -
Removes a header added for the given key.
Declaration
Swift
public func removeHeader(for key: String)
Parameters
key
The name of the header to remove.