Headers

public struct Headers

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 collection

    Declaration

    Swift

    public var startIndex: HeadersIndex
  • The type of an Index of the Headers collection.

    Declaration

    Swift

    public typealias HeadersIndex = HeadersContainer.Index
  • Get a (key value) tuple from the Headers collection at the specified position.

    Declaration

    Swift

    public subscript(position: HeadersIndex) -> (String, String?)

    Parameters

    position

    The position in the Headers collection of the (key, value) tuple to return.

    Return Value

    A (key, value) tuple.

  • Get the value of a HTTP header

    Declaration

    Swift

    public subscript(key: String) -> String?

    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.

  • The ending index of the Headers collection

    Declaration

    Swift

    public var endIndex: HeadersIndex
  • Declaration

    Swift

    public func index(after i: HeadersIndex) -> HeadersIndex

    Parameters

    i

    A valid index of the collection. i must be less than endIndex.

    Return Value

    The index value immediately after i.

  • 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