Skip to main content

ServerBuilder

Struct ServerBuilder 

Source
pub struct ServerBuilder { /* private fields */ }
Expand description

Builds a Server with optional policy and timeout configuration.

You use ServerBuilder when you want a fluent, explicit configuration surface for CORS, custom headers, timeouts, and rate limiting.

§Examples

use http_handle::Server;

let server = Server::builder()
    .address("127.0.0.1:8080")
    .document_root(".")
    .enable_cors()
    .build()
    .expect("valid builder config");

assert_eq!(server.address(), "127.0.0.1:8080");

§Errors

Builder finalization fails when required fields are missing.

§Panics

This type does not panic under normal usage.

Implementations§

Source§

impl ServerBuilder

Source

pub fn new() -> Self

Creates a new builder with no required fields set.

§Examples
use http_handle::server::ServerBuilder;

let builder = ServerBuilder::new();
let _ = builder;
assert_eq!(2 + 2, 4);
§Panics

This function does not panic.

Source

pub fn address(self, address: &str) -> Self

Sets the bind address (ip:port) for the server.

§Examples
use http_handle::Server;

let server = Server::builder()
    .address("127.0.0.1:8080")
    .document_root(".")
    .build()
    .expect("builder should succeed");
assert_eq!(server.address(), "127.0.0.1:8080");
§Panics

This function does not panic.

Source

pub fn document_root(self, path: &str) -> Self

Sets the document root directory used for file resolution.

§Examples
use http_handle::Server;

let server = Server::builder()
    .address("127.0.0.1:8080")
    .document_root(".")
    .build()
    .expect("builder should succeed");
assert_eq!(server.document_root().as_path(), std::path::Path::new("."));
§Panics

This function does not panic.

Source

pub fn enable_cors(self) -> Self

Enables CORS with default settings

Source

pub fn disable_cors(self) -> Self

Disables CORS

Source

pub fn cors_origins(self, origins: Vec<String>) -> Self

Sets allowed CORS origins

Source

pub fn custom_header(self, name: &str, value: &str) -> Self

Adds a custom header that will be included in all responses

Source

pub fn custom_headers(self, headers: HashMap<String, String>) -> Self

Sets multiple custom headers

Source

pub fn request_timeout(self, timeout: Duration) -> Self

Sets the request timeout duration

Source

pub fn connection_timeout(self, timeout: Duration) -> Self

Sets the connection timeout duration

Source

pub fn rate_limit_per_minute(self, requests: usize) -> Self

Sets a simple per-IP request rate limit per minute.

Source

pub fn static_cache_ttl_secs(self, ttl: u64) -> Self

Sets a default static cache max-age (in seconds).

Source

pub fn build(self) -> Result<Server, &'static str>

Finalizes builder state into a Server.

§Examples
use http_handle::Server;

let ok = Server::builder()
    .address("127.0.0.1:8080")
    .document_root(".")
    .build();
assert!(ok.is_ok());
§Errors

Returns Err when:

  • the address was not provided.
  • the document root was not provided.
§Panics

This function does not panic.

Trait Implementations§

Source§

impl Clone for ServerBuilder

Source§

fn clone(&self) -> ServerBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServerBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ServerBuilder

Source§

fn default() -> ServerBuilder

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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