FastCGIServerRequest

public class FastCGIServerRequest : ServerRequest

The FastCGIServerRequest class implements the ServerRequest protocol for incoming HTTP requests that come in over a FastCGI connection. This can be used to read data from the body of the request and process the original request URI.

Usage Example:

 //Create a `FastCGIServerRequest` to handle a new client FastCGI request.
 let request = FastCGIServerRequest(socket: clientSocket)

 //Handle a new client FastCGI request.
 request.parse() { status in
     switch status {
     case .success:
         ...
     break
     case .unsupportedRole:
         ...
     break
     default:
         ...
     break
     }
 }
  • The IP address of the client

    Usage Example:

    print(request.remoteAddress)
    

    Declaration

    Swift

    public private(set) var remoteAddress: String { get }
  • Major version of HTTP of the request

    Usage Example:

    print(String(describing: request.httpVersionMajor))
    

    Declaration

    Swift

    public private(set) var httpVersionMajor: UInt16? { get }
  • Minor version of HTTP of the request

    Usage Example:

    print(String(describing: request.httpVersionMinor))
    

    Declaration

    Swift

    public private(set) var httpVersionMinor: UInt16? { get }
  • The set of HTTP headers received with the incoming request

    Usage Example:

    let protocols = request.headers["Upgrade"]
    

    Declaration

    Swift

    public var headers: HeadersContainer
  • The set of non-HTTP headers received with the incoming request

    Usage Example:

    let protocols = request.fastCGIHeaders["Upgrade"]
    

    Declaration

    Swift

    public var fastCGIHeaders: HeadersContainer
  • The HTTP Method specified in the request

    Usage Example:

    request.method.lowercased()
    

    Declaration

    Swift

    public private(set) var method: String { get }
  • Create and validate the full URL.

    Usage Example:

    print(request.urlURL)
    

    Declaration

    Swift

    public private(set) var urlURL: URL { get }
  • The URL from the request in string form This contains just the path and query parameters starting with ‘/’ Use ‘urlURL’ for the full URL

    Usage Example:

    print(request.urlString)
    

    Declaration

    Swift

    @available(*, deprecated, message: "This contains just the path and query parameters starting with '/'. use 'urlURL' instead")
    public var urlString: String { get }
  • url

    The URL from the request in UTF-8 form This contains just the path and query parameters starting with ‘/’ Use ‘urlURL’ for the full URL

    Usage Example:

    print(request.url)
    

    Declaration

    Swift

    public var url: Data { get }
  • The URL from the request as URLComponents URLComponents has a memory leak on linux as of swift 3.0.1. Use ‘urlURL’ instead

    Usage Example:

    print(request.urlComponents)
    

    Declaration

    Swift

    @available(*, deprecated, message: "URLComponents has a memory leak on linux as of swift 3.0.1. use 'urlURL' instead")
    public lazy var urlComponents: URLComponents { get set }
  • The request ID established by the FastCGI client.

    Usage Example:

    requestId = record.requestId
    

    Declaration

    Swift

    public private(set) var requestId: UInt16 { get }
  • An array of request ID’s that are not our primary one. When the main request is done, the FastCGIServer can reject the extra requests as being unusable.

    Usage Example:

    if request.extraRequestIds.count > 0 {
        ...
    }
    

    Declaration

    Swift

    public private(set) var extraRequestIds: [UInt16] { get }
  • HTTP parser error type. Used when parsing requests from a FastCGI server instance.

    Usage Example:

     //Parse the request from FastCGI and pass back an error type.
     func parse (_ callback: (FastCGIParserErrorType) -> Void) {
         ...
     }
    
    See more

    Declaration

    Swift

    public enum FastCGIParserErrorType
  • Initialize a FastCGIServerRequest instance

    Declaration

    Swift

    required public init(socket: Socket)

    Parameters

    socket

    The socket to read the request from.

  • Read data from the body of the request

    Throws

    Socket.error if an error occurred while reading from the socket.

    Usage Example:

    let readData = try self.read(into: data)
    

    Declaration

    Swift

    public func read(into data: inout Data) throws -> Int

    Parameters

    data

    A Data struct to hold the data read in.

    Return Value

    The number of bytes read.

  • Read all of the data in the body of the request

    Throws

    Socket.error if an error occurred while reading from the socket.

    Usage Example:

    let length = try request.readAllData(into: &body)
    

    Declaration

    Swift

    public func readAllData(into data: inout Data) throws -> Int

    Parameters

    data

    A Data struct to hold the data read in.

    Return Value

    The number of bytes read.

  • Read a string from the body of the request.

    Throws

    Socket.error if an error occurred while reading from the socket.

    Usage Example:

    let body = try request.readString()
    

    Declaration

    Swift

    public func readString() throws -> String?

    Return Value

    An Optional string.