actix / actix-web

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
https://actix.rs
Apache License 2.0
21.6k stars 1.67k forks source link

Middleware - header modification no longer possible #382

Closed jesskfullwood closed 5 years ago

jesskfullwood commented 6 years ago

With the HttpRequest refactor, I can no longer figure out a way to modify the request headers inside a middleware. This is necessary as I am using actix-web as a proxy.

I understand that HttpRequest is now supposed to be immutable, but it would be useful to have some guidance on whether what I aim to achieve is still possible. The Middleware docs still have my use case as a motivating example, but it no longer compiles.

(I'm on the latest master, 82920)

fafhrd91 commented 6 years ago

could you explain why do you need to set headers?

OtaK commented 6 years ago

If you need to "modify" headers, you could simply make your own struct, on which you have way more control, and implement From<HttpRequest> and Into<HttpResponse>. I'm using actix-web kinda like a proxy too (http server in front of a distributed event-driven microservice architecture) and that's what I did, works wonders.

fafhrd91 commented 6 years ago

I am planing to introduce new type of middleware, which will be able to modify request. but timeframe is 3-4 weeks

jesskfullwood commented 6 years ago

In my case, I'm hacking around a corporate firewall which strips certain headers. I am adding them back in.

I could do this at the request handler level but it's easier to do as a middleware (but not a big deal to work around).

DoumanAsh commented 5 years ago

@fafhrd91 Do we plan to change it?

fafhrd91 commented 5 years ago

Yes, we do. We need to switch to actix-http and merge actix-web2

mersinvald commented 5 years ago

@fafhrd91 any updates on that? How can I change request headers within proxy middleware in Actix-Web 0.7.18?

yuana1 commented 5 years ago

@fafhrd91 Is it in progressing?

fafhrd91 commented 5 years ago

i am working on new version, this will take some time

fafhrd91 commented 5 years ago

it is possible in 1.0, i will update docs soon