Module: Perfect-HTTPServer
protocol HeaderListener
This protocol is used to receive headers during HPACK decoding.
func addHeader(name _: [UInt8], value: [UInt8], sensitive: Bool)
A new header field and value has been decoded.
extension HTTPFilter
static func func contentCompression(data: [String:Any]) throws -> HTTPResponseFilter
Response filter which provides content compression.
Mime types which will be encoded or ignored can be specified with the "compressTypes" and
"ignoreTypes" keys, respectively. The values for these keys should be an array of String
containing either the full mime type or the the main type with a * wildcard. e.g. text/*
The default values for the compressTypes key are: "*/*"
The default values for the ignoreTypes key are: "image/*", "video/*", "audio/*"
class HTTPServer
Stand-alone HTTP server.
var documentRoot = "./webroot" { // Given a "safe" default
The directory in which web documents are sought.
Setting the document root will add a default URL route which permits
static files to be served from within.
var serverPort: UInt16 = 0
The port on which the server is listening.
var serverAddress = "0.0.0.0"
The local address on which the server is listening. The default of 0.0.0.0 indicates any address.
var runAsUser: String?
Switch to user after binding port
var serverName = ""
The canonical server name.
This is important if utilizing the `HTTPRequest.serverName` property.
func init()
Initialize the server object.
func addRoutes(_ routes: Routes)
Add the Routes to this server.
func setRequestFilters(_ request: [(HTTPRequestFilter, HTTPFilterPriority)]) -> HTTPServer
Set the request filters. Each is provided along with its priority.
The filters can be provided in any order. High priority filters will be sorted above lower priorities.
Filters of equal priority will maintain the order given here.
func setResponseFilters(_ response: [(HTTPResponseFilter, HTTPFilterPriority)]) -> HTTPServer
Set the response filters. Each is provided along with its priority.
The filters can be provided in any order. High priority filters will be sorted above lower priorities.
Filters of equal priority will maintain the order given here.
func bind() throws
Bind the server to the designated address/port
func start() throws
Start the server. Does not return until the server terminates.
func stop()
Stop the server by closing the accepting TCP socket. Calling this will cause the server to break out of the otherwise blocking `start` function.
extension HTTPServer
struct Server
struct HTTPHandler
static func func staticFiles(data: [String:Any]) throws -> RequestHandler
Returns a handler which will serve static files out of the indicated directory.
If allowResponseFilters is false (which is the default) then the file will be sent in
the most efficient way possible and output filters will be bypassed.
static func func redirect(data: [String:Any]) throws -> RequestHandler
Redirect any matching URI to the server indicated by "base".
The request.uri will be appended to the base.