Skip to main content

Crate product_os_server

Crate product_os_server 

Source
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 support
  • tls: HTTPS/TLS support via rustls
  • dual_server: Dual HTTP/HTTPS protocol support
  • cors: CORS middleware
  • ws: WebSocket support
  • sse: Server-Sent Events support
  • compression: Response compression (gzip, deflate, brotli)
  • cspolicy: Content Security Policy headers
  • csrf: CSRF protection
  • controller: Command and control distributed networking
  • middleware: Extended middleware support
  • extract_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.
BodyBytes
Concrete implementation of (Body).
Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.
Form
URL encoded extractor and response.
Json
JSON Extractor / Response.
ProductOSRouter
Main router struct for Product OS Router
ProductOSServer
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.
ServiceBuilder
Declaratively construct Service values.
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).
Uri
The URI component of a request.

Enums§

ExecutorType
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.
HttpBody
Trait representing a streaming body of a Request or Response.
Layer
Decorates a Service, transforming either the request or the response.
RouterIntoResponse
Trait for generating responses.
Service
An asynchronous function from a Request to a Response.
ServiceExt
An extension trait for Services that provides a variety of convenient adapters

Functions§

service_fn
Returns a new ServiceFn with the given closure.