Struct HttpServer

Source
pub struct HttpServer {
    pub timeout: u64,
    /* private fields */
}
Expand description

A representation of the HTTP server as configured by your process.

Fields§

§timeout: u64

The timeout given for http-server:distro:sys to respond to a configuration request.

Implementations§

Source§

impl HttpServer

Source

pub fn new(timeout: u64) -> Self

Create a new HttpServer with the given timeout.

Source

pub fn bind_http_path<T>( &mut self, path: T, config: HttpBindingConfig, ) -> Result<(), HttpServerError>
where T: Into<String>,

Register a new path with the HTTP server configured using HttpBindingConfig.

Source

pub fn bind_ws_path<T>( &mut self, path: T, config: WsBindingConfig, ) -> Result<(), HttpServerError>
where T: Into<String>,

Register a new path with the HTTP server configured using WsBindingConfig.

Source

pub fn bind_http_static_path<T>( &mut self, path: T, authenticated: bool, local_only: bool, content_type: Option<String>, content: Vec<u8>, ) -> Result<(), HttpServerError>
where T: Into<String>,

Register a new path with the HTTP server, and serve a static file from it. The server will respond to GET requests on this path with the given file.

Source

pub fn secure_bind_http_path<T>( &mut self, path: T, ) -> Result<(), HttpServerError>
where T: Into<String>,

Register a new path with the HTTP server. This will cause the HTTP server to forward any requests on this path to the calling process.

Instead of binding at just a path, this function tells the HTTP server to generate a subdomain with our package ID (with non-ascii-alphanumeric characters converted to -, although will not be needed if package ID is a genuine kimap entry) and bind at that subdomain.

Source

pub fn secure_bind_ws_path<T>(&mut self, path: T) -> Result<(), HttpServerError>
where T: Into<String>,

Register a new WebSocket path with the HTTP server. Any client connections made on this path will be forwarded to this process.

Instead of binding at just a path, this function tells the HTTP server to generate a subdomain with our package ID (with non-ascii-alphanumeric characters converted to -, although will not be needed if package ID is a genuine kimap entry) and bind at that subdomain.

Source

pub fn modify_http_path<T>( &mut self, path: &str, config: HttpBindingConfig, ) -> Result<(), HttpServerError>
where T: Into<String>,

Modify a previously-bound HTTP path.

Source

pub fn modify_ws_path( &mut self, path: &str, config: WsBindingConfig, ) -> Result<(), HttpServerError>

Modify a previously-bound WS path

Source

pub fn unbind_http_path<T>(&mut self, path: T) -> Result<(), HttpServerError>
where T: Into<String>,

Unbind a previously-bound HTTP path.

Source

pub fn unbind_ws_path<T>(&mut self, path: T) -> Result<(), HttpServerError>
where T: Into<String>,

Unbind a previously-bound WebSocket path.

Source

pub fn serve_file( &mut self, file_path: &str, paths: Vec<&str>, config: HttpBindingConfig, ) -> Result<(), HttpServerError>

Serve a file from the given directory within our package drive at the given paths.

The directory is relative to the pkg folder within this package’s drive.

The config static_content field will be ignored in favor of the file content. An error will be returned if the file does not exist.

Source

pub fn serve_file_raw_path( &mut self, file_path: &str, paths: Vec<&str>, config: HttpBindingConfig, ) -> Result<(), HttpServerError>

Serve a file from the given absolute directory.

The config static_content field will be ignored in favor of the file content. An error will be returned if the file does not exist.

Source

pub fn serve_ui( &mut self, directory: &str, roots: Vec<&str>, config: HttpBindingConfig, ) -> Result<(), HttpServerError>

Serve static files from a given directory by binding all of them in http-server to their filesystem path.

The directory is relative to the pkg folder within this package’s drive.

The config static_content field will be ignored in favor of the files’ contents. An error will be returned if the file does not exist.

Source

pub fn handle_websocket_open(&mut self, path: &str, channel_id: u32)

Handle a WebSocket open event from the HTTP server.

Source

pub fn handle_websocket_close(&mut self, channel_id: u32)

Handle a WebSocket close event from the HTTP server.

Source

pub fn parse_request( &self, body: &[u8], ) -> Result<HttpServerRequest, HttpServerError>

Source

pub fn handle_request( &mut self, server_request: HttpServerRequest, http_handler: impl FnMut(IncomingHttpRequest) -> (HttpResponse, Option<KiBlob>), ws_handler: impl FnMut(u32, WsMessageType, KiBlob), )

Handle an incoming request from the HTTP server.

Source

pub fn ws_push_all_channels( &self, path: &str, message_type: WsMessageType, blob: KiBlob, )

Push a WebSocket message to all channels on a given path.

Source

pub fn get_ws_channels(&self) -> HashMap<String, HashSet<u32>>

Source

pub fn bind_multiple_http_paths<T: Into<String>>( &mut self, paths: Vec<T>, config: HttpBindingConfig, ) -> Result<(), HttpServerError>

Register multiple paths with the HTTP server using the same configuration. The security setting is determined by the secure_subdomain field in HttpBindingConfig. All paths must be bound successfully, or none will be bound. If any path fails to bind, all previously bound paths will be unbound before returning the error.

Trait Implementations§

Source§

impl Clone for HttpServer

Source§

fn clone(&self) -> HttpServer

Returns a copy 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 HttpServer

Source§

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

Formats the value using the given formatter. 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.

Source§

impl<T> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,