HeadersContainer

public class HeadersContainer
extension HeadersContainer: Collection

A class that abstracts out the HTTP header APIs of the ServerRequest and ServerResponse protocols.

Usage Example:

 public var headers: HeadersContainer { return httpParser?.headers ?? HeadersContainer() }
  • Creates an instance of HeadersContainer.

    Usage Example:

    let headers = HeaderContainer()
    

    Declaration

    Swift

    public init()
  • Access the value of a HTTP header using subscript syntax.

    Usage Example:

    let subscript: [String]? = headers.subscript(key: "key")
    

    Declaration

    Swift

    public subscript(key: String) -> [String]? { get set }

    Parameters

    key

    The HTTP header key.

    Return Value

    An array of strings representing the set of values for the HTTP header key. If the HTTP header is not found, nil will be returned.

  • Append values to an HTTP header.

    Usage Example:

    header.append(key, value: arrayOfvalues)
    

    Declaration

    Swift

    public func append(_ key: String, value: [String])

    Parameters

    key

    The HTTP header key

    value

    An array of Strings to add as values of the HTTP header.

  • Append values to an HTTP header.

    Usage Example:

    header.append(key, value: value)
    

    Declaration

    Swift

    public func append(_ key: String, value: String)

    Parameters

    key

    The HTTP header key

    value

    An String to br appended to the value of the HTTP header.

  • Remove all of the headers.

    Usage Example:

    header.removeAll()
    

    Declaration

    Swift

    public func removeAll()
  • Declaration

    Swift

    public typealias Index = DictionaryIndex<String, (key: String, value: [String])>
  • The starting index of the HeadersContainer collection

    Declaration

    Swift

    public var startIndex: Index { get }
  • The ending index of the HeadersContainer collection

    Declaration

    Swift

    public var endIndex: Index { get }
  • Get a (key value) tuple from the HeadersContainer collection at the specified position.

    Usage Example:

    header.subscript(position: index)
    

    Declaration

    Swift

    public subscript(position: Index) -> (key: String, value: [String]) { get }

    Parameters

    position

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

    Return Value

    A (key, value) tuple.

  • Get the next index in the HeadersContainer collection after the one specified.

    Usage Example:

    header.index(after: index)
    

    Declaration

    Swift

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

    Parameters

    after

    The Index whose successor is to be returned.

    Return Value

    The Index in the HeadersContainer collection after the one specified.