https://github.com/ym-project/actix-passthrough-headers
Middleware for actix-web to passthrough headers
https://github.com/ym-project/actix-passthrough-headers
actix-web headers middleware passthrough
Last synced: 3 days ago
JSON representation
Middleware for actix-web to passthrough headers
- Host: GitHub
- URL: https://github.com/ym-project/actix-passthrough-headers
- Owner: ym-project
- License: mit
- Created: 2026-04-09T09:07:46.000Z (4 months ago)
- Default Branch: v4
- Last Pushed: 2026-04-09T09:26:20.000Z (4 months ago)
- Last Synced: 2026-06-30T16:18:15.799Z (30 days ago)
- Topics: actix-web, headers, middleware, passthrough
- Language: Rust
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Actix-passthrough-headers
Middleware to passthrough headers. It will be useful when you want to pass header from request to
response without changes.
## Installation
```bash
cargo add actix-passthrough-headers
```
## Usage
```rs
App::new().wrap(PassthroughHeaders::new(vec!["X-Request-Id"]))
```
## Options
By default when route returns some header:
```rs
async fn route() -> HttpResponse {
HttpResponse::Ok()
.insert_header(("X-Request-Id", "2"))
.finish()
}
```
And the same header was passed to middleware:
```rs
App::new().wrap(PassthroughHeaders::new(["X-Request-Id"]))
```
The middleware ignores route's header and returns initial header value. It means when http request
has header `X-Request-Id: 1` and route returns `X-Request-Id: 2`, response header will be
`X-Request-Id: 1`.
### Method preserve_response_headers()
Method `preserve_response_headers` disallow to rewrite route's headers. It means when http request
has header `X-Request-Id: 1` and route returns `X-Request-Id: 2`, response header will be
`X-Request-Id: 2`.
```rs
App::new().wrap(PassthroughHeaders::new(vec!["X-Request-Id"]).preserve_response_headers())
```
## Examples
### Simple Example
```rs
use actix_web::{App, HttpServer};
use actix_passthrough_headers::PassthroughHeaders;
#[actix_web::main]
async fn main() {
HttpServer::new(|| {
App::new().wrap(PassthroughHeaders::new(vec!["X-Request-Id"]))
})
.bind(("127.0.0.1", 8080)).unwrap()
.run()
.await;
}
```
### Preserve response headers example
```rs
use actix_web::{App, HttpServer};
use actix_passthrough_headers::PassthroughHeaders;
async fn route() -> HttpResponse {
HttpResponse::Ok().insert_header(("X-Request-Id", "1")).finish()
}
#[actix_web::main]
async fn main() {
HttpServer::new(|| {
App::new()
.wrap(PassthroughHeaders::new(vec!["X-Request-Id"]).preserve_response_headers())
.route("/", web::get().to(route))
})
.bind(("127.0.0.1", 8080)).unwrap()
.run()
.await;
}
```