FastCGIServer

public class FastCGIServer : Server

A server that listens for incoming HTTP requests that are sent using the FastCGI protocol. This can be used to create a new FastCGIServer and have it listen for conenctions and handle a new client FastCGI request.

Usage Example:

//Create a `FastCGI` server on a specified port.
let server = try FastCGIServer.listen(on: port, delegate: delegate)
  • Declaration

    Swift

    public typealias ServerType = FastCGIServer
  • The ServerDelegate to handle incoming requests.

    Usage Example:

    server.delegate = delegate
    

    Declaration

    Swift

    public var delegate: ServerDelegate?
  • Port number for listening for new connections

    Usage Example:

    self.port = port
    

    Declaration

    Swift

    public private(set) var port: Int? { get }
  • The address of the network interface to listen on. Defaults to nil, which means this server will listen on all interfaces.

    Declaration

    Swift

    public private(set) var address: String? { get }
  • A server state.

    Usage Example:

    self.state = .started
    

    Declaration

    Swift

    public private(set) var state: ServerState { get }
  • Whether or not this server allows port reuse (default: disallowed)

    Usage Example:

    server.allowPortReuse = allowPortReuse
    

    Declaration

    Swift

    public var allowPortReuse: Bool
  • Creates a FastCGI server instance.

    Declaration

    Swift

    public init()
  • Listens for connections on a socket

    Usage Example:

    try server.listen(on: port, address: "localhost")
    

    Declaration

    Swift

    public func listen(on port: Int, address: String? = nil) throws

    Parameters

    on

    port number for new connections

    address

    The address of a network interface to listen on, for example “localhost”. The default is nil, which listens for connections on all interfaces.

  • Static method to create a new FastCGIServer and have it listen for conenctions

    Usage Example:

    let server = try FastCGIServer.listen(on: port, address: "localhost", delegate: delegate)
    

    Declaration

    Swift

    public static func listen(on port: Int, address: String? = nil, delegate: ServerDelegate?) throws -> FastCGIServer

    Parameters

    on

    port number for accepting new connections

    address

    The address of a network interface to listen on, for example “localhost”. The default is nil, which listens for connections on all interfaces.

    delegate

    the delegate handler for FastCGI/HTTP connections

    Return Value

    a new FastCGIServer instance

  • Listens for connections on a socket

    Usage Example:

    server.listen(port: port, errorHandler: errorHandler)
    

    Declaration

    Swift

    @available(*, deprecated, message: "use 'listen(on:﹚ throws' with 'server.failed(callback:﹚' instead")
    public func listen(port: Int, errorHandler: ((Swift.Error) -> Void)? = nil)

    Parameters

    port

    port number for new connections (ex. 9000)

    errorHandler

    optional callback for error handling

  • Static method to create a new FastCGIServer and have it listen for conenctions

    Usage Example:

    let server = FastCGIServer.listen(port: port, delegate: delegate, errorHandler: errorHandler)
    

    Declaration

    Swift

    @available(*, deprecated, message: "use 'listen(on:delegate:﹚ throws' with 'server.failed(callback:﹚' instead")
    public static func listen(port: Int, delegate: ServerDelegate, errorHandler: ((Swift.Error) -> Void)? = nil) -> FastCGIServer

    Parameters

    port

    port number for accepting new connections

    delegate

    the delegate handler for FastCGI/HTTP connections

    errorHandler

    optional callback for error handling

    Return Value

    a new FastCGIServer instance

  • Stop listening for new connections.

    Usage Example:

    server.stop()
    

    Declaration

    Swift

    public func stop()
  • Add a new listener for server being started

    Usage Example:

    server.started(request: request, response: response)
    

    Declaration

    Swift

    @discardableResult
    public func started(callback: @escaping () -> Void) -> Self

    Parameters

    callback

    The listener callback that will run on server successfull start-up

    Return Value

    a FastCGIServer instance

  • Add a new listener for server being stopped

    Usage Example:

    server.stopped(request: request, response: response)
    

    Declaration

    Swift

    @discardableResult
    public func stopped(callback: @escaping () -> Void) -> Self

    Parameters

    callback

    The listener callback that will run when server stops

    Return Value

    a FastCGIServer instance

  • Add a new listener for server throwing an error

    Usage Example:

    server.failed(request: request, response: response)
    

    Declaration

    Swift

    @discardableResult
    public func failed(callback: @escaping (Swift.Error) -> Void) -> Self

    Parameters

    callback

    The listener callback that will run when server throws an error

    Return Value

    a FastCGIServer instance

  • Add a new listener for when listenSocket.acceptClientConnection throws an error

    Usage Example:

    server.clientConnectionFailed() { error in
        ...
    }
    

    Declaration

    Swift

    @discardableResult
    public func clientConnectionFailed(callback: @escaping (Swift.Error) -> Void) -> Self

    Parameters

    callback

    The listener callback that will run

    Return Value

    a Server instance