Struct humphrey::app::App [−][src]
Expand description
Represents the Humphrey app.
The type parameter represents the app state, which is shared between threads.
It must implement the Send
and Sync
traits to be sent between threads.
The state is given to every request as an Arc<State>
.
Implementations
Initialises a new Humphrey app.
Initialising an app like this requires the app state type to implement Default
in order to
automatically generate an initial value for the state. If this requirement is not, or cannnot
be met, please use App::new_with_config
and specify a number of threads and the default
state value.
Initialises a new Humphrey app with the given configuration options.
Runs the Humphrey app on the given socket address. This function will only return if a fatal error is thrown such as the port being in use.
Sets the default state for the server.
Should only be used in cases where the Default
trait cannot be implemented for State
.
For example, if the default state is dynamically generated as it is in the CLI.
pub fn with_route<T>(self, route: &str, handler: T) -> Self where
T: RequestHandler<State> + 'static,
pub fn with_route<T>(self, route: &str, handler: T) -> Self where
T: RequestHandler<State> + 'static,
Adds a route and associated handler to the server.
Routes can include wildcards, for example /blog/*
.
Panics
This function will panic if the route string cannot be converted to a Uri
object.
Sets the error handler for the server.
Sets the connection condition, a function which decides whether to accept the connection. For example, this could be used for implementing whitelists and blacklists.
Sets the websocket handler, a function which processes WebSocket handshakes. This is passed the stream, state, and the request which triggered its calling.
Overrides the default connection handler, allowing for manual control over the TCP requests and responses. Not recommended as it basically disables most of the server’s features.