-
Declaration
Swift
public typealias ServerType = HTTPServer -
Declaration
Swift
public var delegate: ServerDelegate? -
The TCP port on which this server listens for new connections. If
nil, this server does not listen on a TCP socket.Declaration
Swift
public private(set) var port: Int? { get } -
The address of a network interface to listen on, for example “localhost”. The default is nil, which listens for connections on all interfaces.
Declaration
Swift
public private(set) var address: String? { get } -
The Unix domain socket path on which this server listens for new connections. If
nil, this server does not listen on a Unix socket.Declaration
Swift
public private(set) var unixDomainSocketPath: String? { get } -
A server state
Usage Example:
if(httpSever.state == .unknown) { httpServer.stop() }Declaration
Swift
public private(set) var state: ServerState { get set } -
Controls the maximum number of requests per Keep-Alive connection.
Usage Example:
httpServer.keepAliveState = .unlimitedDeclaration
Swift
public var keepAliveState: KeepAliveState -
Whether or not this server allows port reuse (default: disallowed).
Usage Example:
httpServer.allowPortReuse = trueDeclaration
Swift
public var allowPortReuse: Bool -
The EventLoopGroup used by this HTTPServer. This property may be assigned once and once only, by calling
setEventLoopGroup(value:)beforelisten()is called. Server runs oneventLoopGroupwhich it is initialized to i.e. when user explicitly provideseventLoopGroupfor server, public variableeventLoopGroupwill return value stored private variable_eventLoopGroupwhenServerBootstrapis called inlisten()making the server run of userdefined EventLoopGroup. If thesetEventLoopGroup(value:)is not called,nilin variable_eventLoopGroupforces Server to run inglobalELGsince value ofeventLoopGroupinServerBootstrap(group: eventLoopGroup)gets initialzed to valueglobalELGifsetEventLoopGroup(value:)is not called beforelisten()If you are using Kitura-NIO and need to access EventLoopGroup that Kitura uses, you can do so like this:```swift let eventLoopGroup = server.eventLoopGroup ```Declaration
Swift
public var eventLoopGroup: EventLoopGroup { get } -
server configuration
Declaration
Swift
public var options: ServerOptions -
Creates an HTTP server object.
Usage Example:
let config =HTTPServerConfiguration(requestSize: 1000, coonectionLimit: 100) let server = HTTPServer(serverconfig: config) server.listen(on: 8080)Declaration
Swift
public init(options: ServerOptions = ServerOptions()) -
SSL cert configuration for handling client requests.
Usage Example:
httpServer.sslConfig = sslConfigurationDeclaration
Swift
public var sslConfig: SSLService.Configuration? { get set } -
Listens for connections on a Unix socket.
Usage Example:
try server.listen(unixDomainSocketPath: "/my/path")Declaration
Swift
public func listen(unixDomainSocketPath: String) throwsParameters
unixDomainSocketPathUnix socket path for new connections, eg. “/my/path”
-
Listens for connections on a TCP socket.
Usage Example:
try server.listen(on: 8080, address: "localhost")Declaration
Swift
public func listen(on port: Int, address: String? = nil) throwsParameters
onPort number for new connections, e.g. 8080
addressThe address of the network interface to listen on. Defaults to nil, which means this server will listen on all interfaces.
-
Sets the EventLoopGroup to be used by this HTTPServer. This may be called once and once only, and must be called prior to
listen().Throws
If the EventLoopGroup has already been assigned. If you are using Kitura-NIO and need to set EventLoopGroup that Kitura uses, you can do so like this:
```swift server.setEventLoopGroup(EventLoopGroup) ```Declaration
Swift
public func setEventLoopGroup(_ value: EventLoopGroup) throws -
Static method to create a new HTTP server and have it listen for connections.
Usage Example:
let server = HTTPServer.listen(on: 8080, node: "localhost", delegate: self)Declaration
Swift
public static func listen(on port: Int, address: String? = nil, delegate: ServerDelegate?) throws -> ServerTypeParameters
onPort number for accepting new connections.
addressThe address of the network interface to listen on. Defaults to nil, which means this server will listen on all interfaces.
delegateThe delegate handler for HTTP connections.
Return Value
A new instance of a
HTTPServer. -
Static method to create a new HTTP server and have it listen for connections on a Unix domain socket.
Usage Example:
let server = HTTPServer.listen(unixDomainSocketPath: "/my/path", delegate: self)Declaration
Swift
public static func listen(unixDomainSocketPath: String, delegate: ServerDelegate?) throws -> HTTPServerParameters
unixDomainSocketPathThe path of the Unix domain socket that this server should listen on.
delegateThe delegate handler for HTTP connections.
Return Value
A new instance of a
HTTPServer. -
Listen for connections on a socket.
Usage Example:
try server.listen(on: 8080, 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)?)Parameters
portport number for new connections (eg. 8080)
errorHandleroptional callback for error handling
-
Static method to create a new HTTPServer and have it listen for connections.
Usage Example:
let server = HTTPServer(port: 8080, delegate: self, 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)?) -> ServerTypeParameters
portport number for new connections (eg. 8080)
delegateThe delegate handler for HTTP connections.
errorHandleroptional callback for error handling
Return Value
A new
HTTPServerinstance. -
Stop listening for new connections.
Usage Example:
server.stop()Declaration
Swift
public func stop() -
Add a new listener for a server being started.
Usage Example:
server.started(callback: callBack)Declaration
Swift
@discardableResult public func started(callback: @escaping () -> Void) -> SelfParameters
callbackThe listener callback that will run after a successfull start-up.
Return Value
A
HTTPServerinstance. -
Add a new listener for a server being stopped.
Usage Example:
server.stopped(callback: callBack)Declaration
Swift
@discardableResult public func stopped(callback: @escaping () -> Void) -> SelfParameters
callbackThe listener callback that will run when the server stops.
Return Value
A
HTTPServerinstance. -
Add a new listener for a server throwing an error.
Usage Example:
server.started(callback: callBack)Declaration
Swift
@discardableResult public func failed(callback: @escaping (Swift.Error) -> Void) -> SelfParameters
callbackThe listener callback that will run when the server throws an error.
Return Value
A
HTTPServerinstance. -
Add a new listener for when
listenSocket.acceptClientConnectionthrows an error.Usage Example:
server.clientConnectionFailed(callback: callBack)Declaration
Swift
@discardableResult public func clientConnectionFailed(callback: @escaping (Swift.Error) -> Void) -> SelfParameters
callbackThe listener callback that will run on server after successfull start-up.
Return Value
A
HTTPServerinstance.
View on GitHub
HTTPServer Class Reference