Actix-web: Middleware - header modification no longer possible

Created on 10 Jul 2018  路  10Comments  路  Source: actix/actix-web

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)

C-improvement

Most helpful comment

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

All 10 comments

could you explain why do you need to set headers?

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.

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

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).

@fafhrd91 Do we plan to change it?

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

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

@fafhrd91 Is it in progressing?

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

it is possible in 1.0, i will update docs soon

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alex picture alex  路  4Comments

bedax picture bedax  路  3Comments

zhaobingss picture zhaobingss  路  4Comments

sebzim4500 picture sebzim4500  路  3Comments

fafhrd91 picture fafhrd91  路  5Comments