Headers
public struct Headers
extension Headers: Collection
The struct containing the HTTP headers and implements the headers APIs for the
RouterRequest
and RouterResponse
classes.
-
Append values to the header
Declaration
Swift
public mutating func append(_ key: String, value: String)
Parameters
key
The key of the header to append a value to.
value
The value to be appended to the specified header.
-
The starting index of the
Headers
collectionDeclaration
Swift
public var startIndex: HeadersIndex { get }
-
The ending index of the
Headers
collectionDeclaration
Swift
public var endIndex: HeadersIndex { get }
-
The type of an Index of the
Headers
collection.Declaration
Swift
public typealias HeadersIndex = HeadersContainer.Index
-
Get the value of a HTTP header
Declaration
Swift
public subscript(key: String) -> String? { get set }
Parameters
key
The HTTP header key whose value is to be retrieved
Return Value
The value of the specified HTTP header, or nil, if it doesn’t exist.
-
Get a (key value) tuple from the
Headers
collection at the specified position.Declaration
Swift
public subscript(position: HeadersIndex) -> (String, String?) { get }
Parameters
position
The position in the
Headers
collection of the (key, value) tuple to return.Return Value
A (key, value) tuple.
-
Get the next Index in the
Headers
collection after the one specified.Declaration
Swift
public func index(after i: HeadersIndex) -> HeadersIndex
Return Value
The Index in the
Headers
collection after the one specified. -
Sets the Location HTTP header
Declaration
Swift
public mutating func setLocation(_ path: String)
Parameters
path
the path to set into the header or the special reserved word “back”.
-
Sets the Content-Type HTTP header
Declaration
Swift
public mutating func setType(_ type: String, charset: String? = nil)
Parameters
type
The type to set in the Content-Type header
charset
The charset to specify in the Content-Type header.
-
Sets the HTTP header Content-Disposition to “attachment”, optionally adding the filename parameter. If a file is specified the HTTP header Content-Type will be set based on the extension of the specified file.
Declaration
Swift
public mutating func addAttachment(for filePath: String? = nil)
Parameters
for
The file to set the filename to
-
Adds a link with specified parameters to Link HTTP header
Declaration
Swift
public mutating func addLink(_ link: String, linkParameters: [LinkParameter : String])
Parameters
link
link value
linkParameters
The link parameters (according to RFC 5988) with their values