Expand description
Product OS Server
A comprehensive, feature-rich server library supporting HTTP/HTTPS, TLS, WebSockets, Server-Sent Events (SSE), and command-and-control distributed networking.
§Features
- HTTP/HTTPS Servers: Full-featured web servers with TLS support
- Dual Protocol Support: Serve both HTTP and HTTPS simultaneously
- Security: Built-in CSP, CSRF protection, security headers
- Compression: Gzip, Deflate, and Brotli compression support
- WebSockets: Native WebSocket handler support
- SSE: Server-Sent Events for real-time updates
- CORS: Configurable Cross-Origin Resource Sharing
- Command & Control: Distributed network capabilities with authentication
- Flexible Executors: Support for Tokio and custom executors
- no_std Support: Can be used in embedded environments with appropriate features
§Example
use product_os_server::{ProductOSServer, StatusCode, Response, Body};
use product_os_server::ServerConfig;
use product_os_async_executor::TokioExecutor;
// Create server with default configuration
let config = ServerConfig::new();
let mut server: ProductOSServer<(), TokioExecutor, _> =
ProductOSServer::new_with_config(config);
// Add a simple GET handler
async fn hello_handler() -> Result<Response<Body>, StatusCode> {
Ok(Response::new(Body::empty()))
}
server.add_get("/hello", hello_handler);
// Start the server (non-blocking)
// server.start(false).await?;§Feature Flags
core: Core server functionality (hyper, axum, tracing)executor_tokio: Tokio executor supporttls: HTTPS/TLS support via rustlsdual_server: Dual HTTP/HTTPS protocol supportcors: CORS middlewarews: WebSocket supportsse: Server-Sent Events supportcompression: Response compression (gzip, deflate, brotli)cspolicy: Content Security Policy headerscsrf: CSRF protectioncontroller: Command and control distributed networkingmiddleware: Extended middleware supportextract_headers: Typed header extraction
§Safety and Security
This crate provides security features including:
- TLS/HTTPS with rustls
- Content Security Policy configuration
- CSRF token validation
- Security headers (HSTS, X-Frame-Options, etc.)
- Authentication for command-and-control operations
Always review your configuration for your specific security requirements.
Re-exports§
pub use error::ProductOSServerError;pub use error::Result as ServerResult;pub use config::ServerConfig;pub use config::Network;pub use config::Certificate;pub use config::CertificateFiles;pub use config::CertificateFilesKind;pub use config::Compression;
Modules§
- config
- Server configuration types (Network, Certificate, Compression, ServerConfig) Server configuration types
- error
- Error types for server operations. Error types for Product OS Server
Structs§
- Body
- The body type used in axum requests and responses.
- Body
Bytes - Concrete implementation of (Body).
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Form
- URL encoded extractor and response.
- Json
- JSON Extractor / Response.
- ProductOS
Router - Main router struct for Product OS Router
- ProductOS
Server - The main server struct for Product OS Server
- Request
- Represents an HTTP request.
- Response
- Represents an HTTP response
- Router
- The router type for composing handlers and services.
- Service
Builder - Declaratively construct
Servicevalues. - Status
Code - An HTTP status code (
status-codein RFC 9110 et al.). - Uri
- The URI component of a request.
Enums§
- Executor
Type - Specifies which async executor implementation to use for the server.
- Method
- HTTP request method enumeration
Traits§
- Handler
- Trait for async functions that can be used to handle requests.
- Http
Body - Trait representing a streaming body of a Request or Response.
- Layer
- Decorates a
Service, transforming either the request or the response. - Router
Into Response - Trait for generating responses.
- Service
- An asynchronous function from a
Requestto aResponse. - Service
Ext - An extension trait for
Services that provides a variety of convenient adapters
Functions§
- service_
fn - Returns a new
ServiceFnwith the given closure.