-
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 = .unlimited
Declaration
Swift
public var keepAliveState: KeepAliveState
-
Whether or not this server allows port reuse (default: disallowed).
Usage Example:
httpServer.allowPortReuse = true
Declaration
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 oneventLoopGroup
which it is initialized to i.e. when user explicitly provideseventLoopGroup
for server, public variableeventLoopGroup
will return value stored private variable_eventLoopGroup
whenServerBootstrap
is called inlisten()
making the server run of userdefined EventLoopGroup. If thesetEventLoopGroup(value:)
is not called,nil
in variable_eventLoopGroup
forces Server to run inglobalELG
since value ofeventLoopGroup
inServerBootstrap(group: eventLoopGroup)
gets initialzed to valueglobalELG
ifsetEventLoopGroup(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 = sslConfiguration
Declaration
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) throws
Parameters
unixDomainSocketPath
Unix 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) throws
Parameters
on
Port number for new connections, e.g. 8080
address
The 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 -> ServerType
Parameters
on
Port number for accepting new connections.
address
The address of the network interface to listen on. Defaults to nil, which means this server will listen on all interfaces.
delegate
The 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 -> HTTPServer
Parameters
unixDomainSocketPath
The path of the Unix domain socket that this server should listen on.
delegate
The 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
port
port number for new connections (eg. 8080)
errorHandler
optional 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)?) -> ServerType
Parameters
port
port number for new connections (eg. 8080)
delegate
The delegate handler for HTTP connections.
errorHandler
optional callback for error handling
Return Value
A new
HTTPServer
instance. -
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) -> Self
Parameters
callback
The listener callback that will run after a successfull start-up.
Return Value
A
HTTPServer
instance. -
Add a new listener for a server being stopped.
Usage Example:
server.stopped(callback: callBack)
Declaration
Swift
@discardableResult public func stopped(callback: @escaping () -> Void) -> Self
Parameters
callback
The listener callback that will run when the server stops.
Return Value
A
HTTPServer
instance. -
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) -> Self
Parameters
callback
The listener callback that will run when the server throws an error.
Return Value
A
HTTPServer
instance. -
Add a new listener for when
listenSocket.acceptClientConnection
throws an error.Usage Example:
server.clientConnectionFailed(callback: callBack)
Declaration
Swift
@discardableResult public func clientConnectionFailed(callback: @escaping (Swift.Error) -> Void) -> Self
Parameters
callback
The listener callback that will run on server after successfull start-up.
Return Value
A
HTTPServer
instance.