pub struct ServerConfig {
pub http1_enabled: bool,
pub http2: Http2Config,
pub auto_protocol_detection: bool,
pub tls: Option<TlsConfig>,
pub redirect_http_to_https: bool,
pub https_port: Option<u16>,
pub max_request_body_size: usize,
}Expand description
Main server configuration containing all protocol and security settings.
ServerConfig is the primary configuration structure that combines HTTP/1.1,
HTTP/2, TLS, and general server settings. It supports both development and
production scenarios with flexible configuration options.
§Protocol Support
The server can operate in several modes:
- HTTP/1.1 only: Traditional HTTP with optional upgrade support
- HTTP/2 only: Modern binary protocol with multiplexing
- Dual protocol: Automatic negotiation between HTTP/1.1 and HTTP/2
- HTTPS: TLS encryption with ALPN protocol negotiation
§Configuration Patterns
§Development Server
use ignitia::ServerConfig;
let dev_config = ServerConfig {
http1_enabled: true,
auto_protocol_detection: true,
..Default::default()
};§Production HTTPS Server
use ignitia::{ServerConfig, TlsConfig};
let tls_config = TlsConfig::new("cert.pem", "key.pem")
.with_alpn_protocols(vec!["h2", "http/1.1"]);
let prod_config = ServerConfig::default()
.with_tls(tls_config);§HTTP to HTTPS Redirect
use ignitia::ServerConfig;
let redirect_config = ServerConfig::default()
.redirect_to_https(443);Fields§
§http1_enabled: boolEnable HTTP/1.1 protocol support.
When true, the server accepts HTTP/1.1 connections and can handle
traditional HTTP requests. Can be combined with HTTP/2 for dual-protocol support.
§Default
true
§Use Cases
- Legacy client support: Some clients only support HTTP/1.1
- Debugging: HTTP/1.1 is easier to debug with standard tools
- Gradual migration: Maintain compatibility during HTTP/2 rollout
§Performance Considerations
HTTP/1.1 uses more connections for parallelism, which can exhaust server resources faster than HTTP/2’s multiplexing.
http2: Http2ConfigHTTP/2 configuration settings.
Contains all HTTP/2-specific options including flow control, concurrency, and performance tuning parameters.
§Examples
use ignitia::{ServerConfig, Http2Config};
use std::time::Duration;
let custom_http2 = Http2Config {
max_concurrent_streams: Some(2000),
keep_alive_interval: Some(Duration::from_secs(30)),
..Default::default()
};
let config = ServerConfig {
http2: custom_http2,
..Default::default()
};auto_protocol_detection: boolEnable automatic protocol detection and negotiation.
When true, the server automatically determines whether to use HTTP/1.1
or HTTP/2 based on client capabilities and negotiation results.
§Default
true
§Negotiation Methods
- ALPN (TLS): Client and server negotiate protocol during TLS handshake
- HTTP/2 Prior Knowledge: Client sends HTTP/2 directly without upgrade
- HTTP/1.1 Upgrade: Client requests upgrade via HTTP/1.1 headers
§When to Disable
- Force specific protocol version
- Simplified deployment scenarios
- Legacy system integration
tls: Option<TlsConfig>tls only.TLS (Transport Layer Security) configuration.
When provided, enables HTTPS support with customizable cipher suites, protocol versions, and certificate settings.
§Security Best Practices
- Use TLS 1.2 or higher for production
- Configure strong cipher suites
- Implement proper certificate management
- Consider HSTS headers for enhanced security
§Examples
use ignitia::{ServerConfig, TlsConfig, TlsVersion};
let tls_config = TlsConfig::new("server.crt", "server.key")
.tls_versions(TlsVersion::TlsV12, TlsVersion::TlsV13)
.with_alpn_protocols(vec!["h2", "http/1.1"]);
let config = ServerConfig::default().with_tls(tls_config);redirect_http_to_https: boolAutomatically redirect HTTP requests to HTTPS.
When true, all HTTP requests receive a 301 redirect to the equivalent
HTTPS URL. Useful for enforcing encrypted connections.
§Default
false
§Requirements
- Must specify
https_port - HTTPS server must be running on the specified port
- Consider HSTS headers for additional security
§Security Benefits
- Prevents accidental plaintext communication
- Helps meet compliance requirements
- Protects against protocol downgrade attacks
https_port: Option<u16>HTTPS port number for redirect responses.
Used when redirect_http_to_https is true to construct redirect URLs.
Standard HTTPS port is 443, but custom ports are supported.
§Default
None
§Examples
use ignitia::ServerConfig;
// Standard HTTPS port
let config = ServerConfig::default().redirect_to_https(443);
// Custom HTTPS port
let dev_config = ServerConfig::default().redirect_to_https(8443);max_request_body_size: usizeMaximum size of HTTP request body in bytes.
Controls the server-level limit on incoming request body size. Requests with bodies
larger than this limit are immediately rejected with a 413 Payload Too Large response
before reaching any middleware or handlers.
§Server vs Middleware Limits
This server-level limit acts as a hard ceiling and should be set higher than or equal to any middleware body size limits. The processing order is:
- Server limit (this setting) - Applied first during request parsing
- Middleware limits - Applied during middleware processing
- Handler processing - Only reached if all limits pass
§Default
10 * 1024 * 1024 (10MB)
§Security Considerations
- DoS Protection: Prevents memory exhaustion from extremely large requests
- Resource Management: Limits server memory usage per connection
- Early Rejection: Saves processing cycles by rejecting oversized requests immediately
§Performance Impact
- Low limits (1-10MB): Good for APIs with small payloads (JSON, forms)
- Medium limits (10-100MB): Suitable for file uploads, media processing
- High limits (100MB-1GB+): For bulk data transfer, video uploads
§Examples
§API Server (Small Payloads)
use ignitia::ServerConfig;
let api_config = ServerConfig::default()
.with_max_request_body_size(5 * 1024 * 1024); // 5MB§File Upload Server
use ignitia::ServerConfig;
let upload_config = ServerConfig::default()
.with_max_request_body_size(500 * 1024 * 1024); // 500MB§High-Volume Data Processing
use ignitia::ServerConfig;
let bulk_config = ServerConfig::default()
.with_max_request_body_size(2 * 1024 * 1024 * 1024); // 2GB§Middleware Coordination
use ignitia::{ServerConfig, Router, middleware::BodySizeLimitMiddleware};
// Server allows up to 100MB (safety net)
let config = ServerConfig::default()
.with_max_request_body_size(100 * 1024 * 1024);
// Middleware enforces 50MB business logic limit
let router = Router::new()
.middleware(BodySizeLimitMiddleware::new(50 * 1024 * 1024));§Error Handling
When this limit is exceeded, the server returns:
- Status:
413 Payload Too Large - Body:
"Request too large" - Timing: Before any middleware or handlers execute
For custom error handling, ensure middleware limits are lower than this value.
Implementations§
Source§impl ServerConfig
impl ServerConfig
Sourcepub fn with_tls(self, tls_config: TlsConfig) -> Self
Available on crate feature tls only.
pub fn with_tls(self, tls_config: TlsConfig) -> Self
tls only.Configure the server to use TLS encryption.
Enables HTTPS support with the provided TLS configuration. The TLS config includes certificate paths, cipher suites, protocol versions, and ALPN settings.
§Arguments
tls_config- Complete TLS configuration including certificates and security settings
§Returns
Modified ServerConfig with TLS enabled
§Examples
use ignitia::{ServerConfig, TlsConfig};
let tls_config = TlsConfig::new("server.crt", "private.key")
.with_alpn_protocols(vec!["h2", "http/1.1"]);
let server_config = ServerConfig::default()
.with_tls(tls_config);
assert!(server_config.is_tls_enabled());§Security Considerations
- Ensure certificate files are properly secured
- Use strong cipher suites and recent TLS versions
- Consider certificate rotation and renewal processes
- Implement proper key management practices
Sourcepub fn redirect_to_https(self, https_port: u16) -> Self
pub fn redirect_to_https(self, https_port: u16) -> Self
Enable automatic HTTP to HTTPS redirection.
Configures the server to send 301 Moved Permanently responses for all HTTP requests, redirecting clients to the equivalent HTTPS URL.
§Arguments
https_port- Port number where HTTPS server is listening
§Returns
Modified ServerConfig with redirect enabled
§Redirect Behavior
- Preserves the original path and query string
- Uses 301 status code for permanent redirect
- Handles both standard (443) and custom HTTPS ports
§Examples
use ignitia::ServerConfig;
// Redirect to standard HTTPS port
let config = ServerConfig::default().redirect_to_https(443);
// Redirect to custom port for development
let dev_config = ServerConfig::default().redirect_to_https(8443);
assert_eq!(config.redirect_http_to_https, true);
assert_eq!(config.https_port, Some(443));§Production Deployment
use ignitia::{ServerConfig, TlsConfig};
let production_config = ServerConfig::default()
.with_tls(TlsConfig::new("cert.pem", "key.pem"))
.redirect_to_https(443);§Security Benefits
- Enforces encrypted communication
- Prevents accidental plaintext data transmission
- Improves compliance with security standards
- Protects against man-in-the-middle attacks
Sourcepub fn is_tls_enabled(&self) -> bool
Available on crate feature tls only.
pub fn is_tls_enabled(&self) -> bool
tls only.Check if TLS/HTTPS is enabled in the current configuration.
Returns true if a TLS configuration has been provided, indicating
that the server will support HTTPS connections.
§Returns
true if TLS is configured, false otherwise
§Examples
use ignitia::ServerConfig;
let http_config = ServerConfig::default();
assert_eq!(http_config.is_tls_enabled(), false);
{
use ignitia::TlsConfig;
let https_config = ServerConfig::default()
.with_tls(TlsConfig::new("cert.pem", "key.pem"));
assert_eq!(https_config.is_tls_enabled(), true);
}§Use Cases
- Conditional logic based on security configuration
- Validation of server setup
- Dynamic port binding decisions
- Logging and monitoring setup
Sourcepub fn with_max_request_body_size(self, size: usize) -> Self
pub fn with_max_request_body_size(self, size: usize) -> Self
Configure the maximum allowed request body size in bytes.
Sets the server-level hard limit for HTTP request body size. This limit is enforced before any middleware processing and provides DoS protection against extremely large requests.
§Arguments
size- Maximum body size in bytes
§Returns
Modified ServerConfig with the new body size limit
§Recommendations
Choose based on your use case:
- REST APIs: 1-10MB for JSON payloads
- File uploads: 50-500MB depending on file types
- Bulk data: 1GB+ for data processing applications
- Development: Higher limits for testing flexibility
Always set higher than middleware limits:
use ignitia::{ServerConfig, Router};
// Server: 100MB safety limit
let config = ServerConfig::default()
.with_max_request_body_size(100 * 1024 * 1024);
// Middleware: 50MB business logic limit
let router = Router::new()
.middleware(/* body size middleware with 50MB limit */);§Examples
§Conservative API Server
use ignitia::ServerConfig;
let config = ServerConfig::default()
.with_max_request_body_size(1024 * 1024); // 1MB§Media Upload Service
use ignitia::ServerConfig;
let config = ServerConfig::default()
.with_max_request_body_size(1024 * 1024 * 1024); // 1GB§Development Environment
use ignitia::ServerConfig;
let config = ServerConfig::default()
.with_max_request_body_size(5 * 1024 * 1024 * 1024); // 5GB for testing§Security Impact
- Too Low: Legitimate requests may be rejected
- Too High: Server vulnerable to memory exhaustion attacks
- Balanced: Protects server while allowing intended use cases
Trait Implementations§
Source§impl Clone for ServerConfig
impl Clone for ServerConfig
Source§fn clone(&self) -> ServerConfig
fn clone(&self) -> ServerConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ServerConfig
impl Debug for ServerConfig
Source§impl Default for ServerConfig
impl Default for ServerConfig
Source§fn default() -> Self
fn default() -> Self
Creates a default server configuration suitable for development and testing.
The default configuration enables both HTTP/1.1 and HTTP/2 with automatic protocol detection. TLS is disabled by default for easier development setup.
§Default Values
http1_enabled:true- Support legacy clientshttp2:Http2Config::default()- Optimized HTTP/2 settingsauto_protocol_detection:true- Automatic negotiationtls:None- No TLS (HTTP only)redirect_http_to_https:false- No automatic redirecthttps_port:None- No HTTPS port specified
§Production Considerations
For production deployments, consider:
- Enabling TLS with proper certificates
- Configuring HTTP to HTTPS redirect
- Tuning HTTP/2 settings for your workload
- Implementing proper logging and monitoring
§Examples
use ignitia::ServerConfig;
let config = ServerConfig::default();
assert_eq!(config.http1_enabled, true);
assert_eq!(config.auto_protocol_detection, true);
assert!(config.tls.is_none());