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
keyThe key of the header to append a value to.
valueThe value to be appended to the specified header.
-
The starting index of the
HeaderscollectionDeclaration
Swift
public var startIndex: HeadersIndex { get } -
The ending index of the
HeaderscollectionDeclaration
Swift
public var endIndex: HeadersIndex { get } -
The type of an Index of the
Headerscollection.Declaration
Swift
public typealias HeadersIndex = HeadersContainer.Index -
Get the value of a HTTP header
Declaration
Swift
public subscript(key: String) -> String? { get set }Parameters
keyThe 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
Headerscollection at the specified position.Declaration
Swift
public subscript(position: HeadersIndex) -> (String, String?) { get }Parameters
positionThe position in the
Headerscollection of the (key, value) tuple to return.Return Value
A (key, value) tuple.
-
Get the next Index in the
Headerscollection after the one specified.Declaration
Swift
public func index(after i: HeadersIndex) -> HeadersIndexReturn Value
The Index in the
Headerscollection after the one specified. -
Sets the Location HTTP header
Declaration
Swift
public mutating func setLocation(_ path: String)Parameters
paththe 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
typeThe type to set in the Content-Type header
charsetThe 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
forThe 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
linklink value
linkParametersThe link parameters (according to RFC 5988) with their values
View on GitHub
Headers Structure Reference