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
impl HttpServer
Sourcepub fn bind_http_path<T>(
&mut self,
path: T,
config: HttpBindingConfig,
) -> Result<(), HttpServerError>
pub fn bind_http_path<T>( &mut self, path: T, config: HttpBindingConfig, ) -> Result<(), HttpServerError>
Register a new path with the HTTP server configured using HttpBindingConfig
.
Sourcepub fn bind_ws_path<T>(
&mut self,
path: T,
config: WsBindingConfig,
) -> Result<(), HttpServerError>
pub fn bind_ws_path<T>( &mut self, path: T, config: WsBindingConfig, ) -> Result<(), HttpServerError>
Register a new path with the HTTP server configured using WsBindingConfig
.
Sourcepub fn bind_http_static_path<T>(
&mut self,
path: T,
authenticated: bool,
local_only: bool,
content_type: Option<String>,
content: Vec<u8>,
) -> Result<(), HttpServerError>
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>
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.
Sourcepub fn secure_bind_http_path<T>(
&mut self,
path: T,
) -> Result<(), HttpServerError>
pub fn secure_bind_http_path<T>( &mut self, path: T, ) -> Result<(), HttpServerError>
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.
Sourcepub fn secure_bind_ws_path<T>(&mut self, path: T) -> Result<(), HttpServerError>
pub fn secure_bind_ws_path<T>(&mut self, path: T) -> Result<(), HttpServerError>
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.
Sourcepub fn modify_http_path<T>(
&mut self,
path: &str,
config: HttpBindingConfig,
) -> Result<(), HttpServerError>
pub fn modify_http_path<T>( &mut self, path: &str, config: HttpBindingConfig, ) -> Result<(), HttpServerError>
Modify a previously-bound HTTP path.
Sourcepub fn modify_ws_path(
&mut self,
path: &str,
config: WsBindingConfig,
) -> Result<(), HttpServerError>
pub fn modify_ws_path( &mut self, path: &str, config: WsBindingConfig, ) -> Result<(), HttpServerError>
Modify a previously-bound WS path
Sourcepub fn unbind_http_path<T>(&mut self, path: T) -> Result<(), HttpServerError>
pub fn unbind_http_path<T>(&mut self, path: T) -> Result<(), HttpServerError>
Unbind a previously-bound HTTP path.
Sourcepub fn unbind_ws_path<T>(&mut self, path: T) -> Result<(), HttpServerError>
pub fn unbind_ws_path<T>(&mut self, path: T) -> Result<(), HttpServerError>
Unbind a previously-bound WebSocket path.
Sourcepub fn serve_file(
&mut self,
file_path: &str,
paths: Vec<&str>,
config: HttpBindingConfig,
) -> Result<(), HttpServerError>
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.
Sourcepub fn serve_file_raw_path(
&mut self,
file_path: &str,
paths: Vec<&str>,
config: HttpBindingConfig,
) -> Result<(), HttpServerError>
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.
Sourcepub fn serve_ui(
&mut self,
directory: &str,
roots: Vec<&str>,
config: HttpBindingConfig,
) -> Result<(), HttpServerError>
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.
Sourcepub fn handle_websocket_open(&mut self, path: &str, channel_id: u32)
pub fn handle_websocket_open(&mut self, path: &str, channel_id: u32)
Handle a WebSocket open event from the HTTP server.
Sourcepub fn handle_websocket_close(&mut self, channel_id: u32)
pub fn handle_websocket_close(&mut self, channel_id: u32)
Handle a WebSocket close event from the HTTP server.
pub fn parse_request( &self, body: &[u8], ) -> Result<HttpServerRequest, HttpServerError>
Sourcepub fn handle_request(
&mut self,
server_request: HttpServerRequest,
http_handler: impl FnMut(IncomingHttpRequest) -> (HttpResponse, Option<KiBlob>),
ws_handler: impl FnMut(u32, WsMessageType, KiBlob),
)
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.
Sourcepub fn ws_push_all_channels(
&self,
path: &str,
message_type: WsMessageType,
blob: KiBlob,
)
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.
pub fn get_ws_channels(&self) -> HashMap<String, HashSet<u32>>
Sourcepub fn bind_multiple_http_paths<T: Into<String>>(
&mut self,
paths: Vec<T>,
config: HttpBindingConfig,
) -> Result<(), HttpServerError>
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
impl Clone for HttpServer
Source§fn clone(&self) -> HttpServer
fn clone(&self) -> HttpServer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for HttpServer
impl RefUnwindSafe for HttpServer
impl Send for HttpServer
impl Sync for HttpServer
impl Unpin for HttpServer
impl UnwindSafe for HttpServer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more