TLS (HTTPS)
Warning: According to the project's
CHANGELOG.md, the built-intlsfeature was removed in version0.4.0. The information below may be outdated and is provided for users of older versions ofwarp.
warp previously offered a built-in way to serve your application over TLS (HTTPS), securing the communication between the server and the client.
Historical Usage
When the tls feature was enabled, you could configure and run a TLS server using a builder pattern on warp::serve.
Here is an example based on examples/tls.rs demonstrating how it was used:
// This example requires the 'tls' feature, which is removed in v0.4.0
#[cfg(feature = "tls")]
async fn run_tls_server() {
use warp::Filter;
let routes = warp::any().map(|| "Hello, Secure World!");
warp::serve(routes)
.tls()
// Specify the path to your certificate and private key files
.cert_path("examples/tls/cert.pem")
.key_path("examples/tls/key.rsa")
.run(([127, 0, 0, 1], 3030))
.await;
}
This setup involved:
- Calling
.tls()on theServerinstance. - Providing the path to a PEM-encoded certificate file via
.cert_path(). - Providing the path to a PEM-encoded private key file (RSA or ECC) via
.key_path().
Modern Approach
For warp versions 0.4.0 and newer, you should handle TLS termination at a layer above warp. Common approaches include:
- Using a Reverse Proxy: Deploy a reverse proxy like Nginx, Caddy, or Traefik in front of your
warpapplication. The proxy handles TLS termination and forwards plain HTTP traffic to yourwarpserver. This is a common and recommended practice for production deployments. - Using a library like
hyper-rustls: Manually create an acceptor that wraps incoming TCP streams with a TLS layer before they are passed towarp's server.