PropagateHeaderMiddleware
struct PropagateHeaderMiddleware
Middleware for propagating a header from the request to the response.
Example
nv
use std.net.http.server.{
middlewares.PropagateHeaderMiddleware,
Router,
};
let app = Router.new().with(PropagateHeaderMiddleware.new(["x-request-id"]));
Implementions
Methods
new
pub fn new(headers: [string]): PropagateHeaderMiddleware
[src]
pub fn new(headers: [string]): PropagateHeaderMiddleware {
return PropagateHeaderMiddleware { headers: headers };
}
Creates a new PropagateHeaderMiddleware
middleware.
new
pub fn new(headers: [string]): PropagateHeaderMiddleware
[src]
pub fn new(headers: [string]): PropagateHeaderMiddleware {
return PropagateHeaderMiddleware { headers: headers };
}
Creates a new PropagateHeaderMiddleware
middleware.
Creates a new PropagateHeaderMiddleware
middleware.
[src]
pub fn transform(self, handler: Handler): Handler {
return handler
.around(|handler, request| {
let new_headers: <string, string> = {:};
for (let key in self.headers) {
if (let value = request.headers().get(key)) {
new_headers.set(key, value);
}
}
let response = try handler.handle(request);
for (let key, val in new_headers) {
response.headers().append(key, val);
}
return response;
});
}
[src]
pub fn transform(self, handler: Handler): Handler {
return handler
.around(|handler, request| {
let new_headers: <string, string> = {:};
for (let key in self.headers) {
if (let value = request.headers().get(key)) {
new_headers.set(key, value);
}
}
let response = try handler.handle(request);
for (let key, val in new_headers) {
response.headers().append(key, val);
}
return response;
});
}