RouterResponse

public class RouterResponse

Router response that the server sends as a reply to RouterRequest.

  • Set of cookies to return with the response.

    Declaration

    Swift

    public var cookies = [String: HTTPCookie]()
  • Optional error value.

    Declaration

    Swift

    public var error: Swift.Error?
  • HTTP headers of the response.

    Declaration

    Swift

    public var headers: Headers
  • HTTP status code of the response.

    Declaration

    Swift

    public var statusCode: HTTPStatusCode
  • End the response.

    Throws

    Socket.Error if an error occurred while writing to a socket.

    Declaration

    Swift

    public func end() throws
  • Send a string.

    Declaration

    Swift

    public func send(_ str: String) -> RouterResponse

    Parameters

    str

    the string to send.

    Return Value

    this RouterResponse.

  • Send data.

    Declaration

    Swift

    public func send(data: Data) -> RouterResponse

    Parameters

    data

    the data to send.

    Return Value

    this RouterResponse.

  • Send a file.

    Throws

    An error in the Cocoa domain, if the file cannot be read.

    Note

    Sets the Content-Type header based on the extension of the file. If the fileName is relative, it is relative to the current directory.

    Declaration

    Swift

    public func send(fileName: String) throws -> RouterResponse

    Parameters

    fileName

    the name of the file to send.

    Return Value

    this RouterResponse.

  • Send JSON.

    Declaration

    Swift

    public func send(json: JSON) -> RouterResponse

    Parameters

    json

    the JSON object to send.

    Return Value

    this RouterResponse.

  • Send JSON.

    Declaration

    Swift

    public func send(json: [Any]) -> RouterResponse

    Parameters

    json

    The array to send in JSON format.

    Return Value

    this RouterResponse.

  • Send JSON.

    Declaration

    Swift

    public func send(json: [String: Any]) -> RouterResponse

    Parameters

    json

    The Dictionary to send in JSON format as a hash.

    Return Value

    this RouterResponse.

  • Send JSON with JSONP callback.

    Throws

    JSONPError.invalidCallbackName if the the callback query parameter of the request URL is missing or its value is empty or contains invalid characters (the set of valid characters is the alphanumeric characters and []$._).

    Declaration

    Swift

    public func send(jsonp: JSON, callbackParameter: String = "callback") throws -> RouterResponse

    Parameters

    json

    the JSON object to send.

    callbackParameter

    the name of the URL query parameter whose value contains the JSONP callback function.

    Return Value

    this RouterResponse.

  • Set the status code.

    Declaration

    Swift

    public func status(_ status: HTTPStatusCode) -> RouterResponse

    Parameters

    status

    the HTTP status code object.

    Return Value

    this RouterResponse.

  • Send the HTTP status code.

    Declaration

    Swift

    public func send(status: HTTPStatusCode) -> RouterResponse

    Parameters

    status

    the HTTP status code.

    Return Value

    this RouterResponse.

  • Redirect to path with status code.

    Throws

    Socket.Error if an error occurred while writing to a socket.

    Declaration

    Swift

    public func redirect(_ path: String, status: HTTPStatusCode = .movedTemporarily) throws -> RouterResponse

    Return Value

    this RouterResponse.

  • Undocumented

    Declaration

    Swift

    public class RouterResponse
  • Set headers and attach file for downloading.

    Throws

    An error in the Cocoa domain, if the file cannot be read.

    Declaration

    Swift

    public func send(download: String) throws

    Parameters

    download

    the file to download.

  • Set the pre-flush lifecycle handler and return the previous one.

    Declaration

    Swift

    public func setOnEndInvoked(_ newOnEndInvoked: @escaping LifecycleHandler) -> LifecycleHandler

    Parameters

    newOnEndInvoked

    The new pre-flush lifecycle handler.

    Return Value

    The old pre-flush lifecycle handler.

  • Set the written data filter and return the previous one.

    Declaration

    Swift

    public func setWrittenDataFilter(_ newWrittenDataFilter: @escaping WrittenDataFilter) -> WrittenDataFilter

    Parameters

    newWrittenDataFilter

    The new written data filter.

    Return Value

    The old written data filter.

  • Perform content-negotiation on the Accept HTTP header on the request, when present.

    Uses request.accepts() to select a handler for the request, based on the acceptable types ordered by their quality values. If the header is not specified, the default callback is invoked. When no match is found, the server invokes the default callback if exists, or responds with 406 “Not Acceptable”. The Content-Type response header is set when a callback is selected.

    Throws

    Socket.Error if an error occurred while writing to a socket.

    Declaration

    Swift

    public func format(callbacks: [String : ((RouterRequest, RouterResponse) -> Void)]) throws

    Parameters

    callbacks

    a dictionary that maps content types to handlers.