pub struct Server { /* private fields */ }
Expand description

An HTTP server.

use astra::{Body, Request, Response, Server};

Server::bind("localhost:3000")
    .serve(|mut req: Request| {
        println!("incoming {:?}", req.uri());
        Response::new(Body::new("Hello World!"))
    })
    .expect("failed to start server");

See the crate-level documentation for details.

Implementations

Binds a server to the provided address.

use astra::Server;
use std::net::SocketAddr;

let server = Server::bind("localhost:3000");
let server = Server::bind(SocketAddr::from(([127, 0, 0, 1], 3000)));
Panics

This method will panic if binding to the address fails.

Serve incoming connections with the provided service.

use astra::{Body, Request, Response, Server};

Server::bind("localhost:3000")
    .serve(|mut req: Request| {
        println!("incoming {:?}", req.uri());
        Response::new(Body::new("Hello World!"))
    })
    .expect("failed to start server");

Sets the maximum number of threads in the worker pool.

By default, the limit is 15 threads per CPU core.

Sets how long to keep alive an idle thread in the worker pool.

By default, the timeout is set to 6 seconds.

Sets whether to use keep-alive for HTTP/1 connections.

Default is true.

Set whether HTTP/1 connections should support half-closures.

Clients can chose to shutdown their write-side while waiting for the server to respond. Setting this to true will prevent closing the connection immediately if read detects an EOF in the middle of a request.

Default is false.

Set the maximum buffer size.

Default is ~ 400kb.

Sets whether to bunch up HTTP/1 writes until the read buffer is empty.

This isn’t really desirable in most cases, only really being useful in silly pipeline benchmarks.

Set whether HTTP/1 connections should try to use vectored writes, or always flatten into a single buffer.

Note that setting this to false may mean more copies of body data, but may also improve performance when an IO transport doesn’t support vectored writes well, such as most TLS implementations.

Setting this to true will force hyper to use queued strategy which may eliminate unnecessary cloning on some TLS backends

Default is auto. In this mode hyper will try to guess which mode to use

Set whether HTTP/1 connections will write header names as title case at the socket level.

Note that this setting does not affect HTTP/2.

Default is false.

Set whether to support preserving original header cases.

Currently, this will record the original cases received, and store them in a private extension on the Request. It will also look for and use such an extension in any provided Response.

Since the relevant extension is still private, there is no way to interact with the original cases. The only effect this can have now is to forward the cases in a proxy-like fashion.

Note that this setting does not affect HTTP/2.

Default is false.

Sets whether HTTP/1 is required.

Default is false.

Sets whether HTTP/2 is required.

Default is false.

Sets the SETTINGS_INITIAL_WINDOW_SIZE option for HTTP2 stream-level flow control.

Passing None will do nothing.

If not set, hyper will use a default.

Sets the max connection-level flow control for HTTP2

Passing None will do nothing.

If not set, hyper will use a default.

Sets whether to use an adaptive flow control.

Enabling this will override the limits set in http2_initial_stream_window_size and http2_initial_connection_window_size.

Sets the maximum frame size to use for HTTP2.

Passing None will do nothing.

If not set, hyper will use a default.

Sets the SETTINGS_MAX_CONCURRENT_STREAMS option for HTTP2 connections.

Default is no limit (std::u32::MAX). Passing None will do nothing.

Set the maximum write buffer size for each HTTP/2 stream.

Default is currently ~400KB, but may change.

Panics

The value must be no larger than u32::MAX.

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more