pub struct Server {}Implementations§
Source§impl Server
impl Server
pub fn process_request( stream: impl Read + Write + Unpin, peer_addr: SocketAddr, ) -> Vec<u8> ⓘ
pub fn bad_request_response(message: String) -> Vec<u8> ⓘ
Sourcepub fn payload_too_large_response(message: String) -> Vec<u8> ⓘ
pub fn payload_too_large_response(message: String) -> Vec<u8> ⓘ
Builds a 413 Payload Too Large raw response for a request whose declared
Content-Length exceeds RWS_CONFIG_MAX_BODY_SIZE_IN_BYTES. The connection
is always closed after this is sent (see Server::process) — the client’s
unread body bytes are still queued on the socket, so keep-alive framing
can’t be trusted.
Sourcepub fn header_fields_too_large_response() -> Vec<u8> ⓘ
pub fn header_fields_too_large_response() -> Vec<u8> ⓘ
Builds a 431 Request Header Fields Too Large raw response for a
request head longer than [framing::MAX_HEAD_SIZE]. The connection is
closed after it: the rest of the oversized head is still unread.
Sourcepub fn request_timeout_response() -> Vec<u8> ⓘ
pub fn request_timeout_response() -> Vec<u8> ⓘ
Builds a 408 Request Timeout raw response for a client that started
a request head but didn’t finish it within REQUEST_HEAD_TIMEOUT.
The connection is closed after it.
Sourcepub fn continue_response() -> Vec<u8> ⓘ
pub fn continue_response() -> Vec<u8> ⓘ
Builds the 100 Continue interim response (RFC 9110 §15.2.1) — no
headers, no body, just the status line. Sent immediately after parsing
a request with Expect: 100-continue, before reading its body, so the
client (which is waiting for this before it uploads the body) doesn’t
stall or time out. See Server::process for where this is sent from.
Sourcepub fn expectation_failed_response(message: String) -> Vec<u8> ⓘ
pub fn expectation_failed_response(message: String) -> Vec<u8> ⓘ
Builds a 417 Expectation Failed raw response for an Expect header
value other than 100-continue (RFC 9110 §10.1.1) — the only
expectation this server understands. Sent instead of reading the
request body, since the expectation can’t be met either way.
pub fn process( stream: impl Read + Write + Unpin, connection: ConnectionInfo, app: impl Application, ) -> Result<(), String>
Sourcepub fn setup() -> Result<(TcpListener, ThreadPool), String>
pub fn setup() -> Result<(TcpListener, ThreadPool), String>
Reads configuration (IP, port, thread count, TLS paths) from the layered config system
and returns a bound TcpListener and a sized ThreadPool. Call once at startup.
Sourcepub fn run(
listener: TcpListener,
pool: ThreadPool,
app: impl Application + Send + Clone + 'static,
)
pub fn run( listener: TcpListener, pool: ThreadPool, app: impl Application + Send + Clone + 'static, )
Accepts TCP connections in a loop and dispatches each to the thread pool.
When built with the http1 feature, Ctrl+C and SIGTERM stop the accept
loop gracefully: SERVER_READY is cleared and the pool drains all
in-flight connections before returning.
For TLS/HTTP2/HTTP3 use Server::run_tls.
Source§impl Server
impl Server
pub async fn run_tls( listener: TcpListener, pool: ThreadPool, app: impl Application + Send + Clone + 'static, )
http2 only.Sourcepub async fn run_plain(
listener: TcpListener,
app: impl Application + Send + Clone + 'static,
)
Available on crate feature http2 only.
pub async fn run_plain( listener: TcpListener, app: impl Application + Send + Clone + 'static, )
http2 only.Plain-HTTP accept loop of the async builds (used by run_tls when no
certificate is configured): one tokio task per connection via
http1_async::serve, so idle or slow clients can’t exhaust a thread
pool. An accept error (e.g. out of file descriptors) backs off briefly
and keeps serving instead of ending the loop.
Sourcepub async fn run_redirect()
Available on crate feature http2 only.
pub async fn run_redirect()
http2 only.Binds a plain-HTTP listener on the port in RWS_CONFIG_HTTP_REDIRECT_PORT and sends
301 Moved Permanently to the HTTPS equivalent of every incoming URL.
Returns immediately if TLS is not configured or the redirect port is not set.
Auto Trait Implementations§
impl Freeze for Server
impl RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
impl UnwindSafe for Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
map-response-body only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.