MoosicBox Middleware
Basic HTTP middleware collection for the MoosicBox web server ecosystem, providing request logging and service information utilities for Actix Web applications.
Features
- API Logger: Request/response logging middleware with timing and status tracking
- Service Info: Middleware for adding service information to responses
- Tunnel Info: Optional middleware for tunnel-based requests
Installation
Add this to your Cargo.toml:
[]
= "0.1.1"
# Enable tunnel middleware
= { = "0.1.1", = ["tunnel"] }
Usage
API Logger Middleware
use ApiLogger;
use ;
async
async
The API logger middleware provides:
- Request method, path, and query string logging
- Relevant headers logging (Range, Content-Range, Accept-Ranges, Content-Length)
- Response status and timing information
- Success/failure status tracking
- Error details for failed requests
Service Info Middleware
use ServiceInfo;
use ;
async
async
Tunnel Info Middleware (Optional)
When the tunnel feature is enabled:
use TunnelInfo;
use ;
async
async
Middleware Details
ApiLogger
The ApiLogger middleware logs:
- Request Start: Method, path, query string, and relevant headers
- Request End: Response status, timing, and relevant response headers
- Success/Failure: Different log levels for success vs. error responses
- Error Details: Full error information for debugging
Log output example:
TRACE GET /api/tracks?limit=10 headers=[("range", "bytes=0-1023")] STARTED
TRACE GET /api/tracks?limit=10 headers=[("range", "bytes=0-1023")] resp_headers=[("content-length", "2048"), ("accept-ranges", "bytes")] FINISHED SUCCESS "200 OK" (25 ms)
ServiceInfo
The ServiceInfo middleware adds service metadata to responses for identification and monitoring purposes.
TunnelInfo
The TunnelInfo middleware handles tunnel-specific request processing when tunnel features are enabled.
Core Components
// API Logger
;
;
// Service Info
;
;
// Tunnel Info (feature-gated)
;
;
Dependencies
actix_web: Web framework for middleware integrationfutures-util: For async middleware implementationlog: For logging functionalitytracing: For structured logging support
This middleware collection provides essential request logging and service identification capabilities for MoosicBox web services.