0

I'm trying to redirect requests to some URL. My server is using rust with warp.

The library https://docs.rs/warp-reverse-proxy/latest/warp_reverse_proxy/ seems to do exactly what I need, but when it redirects with all the headers the server receiving the request rejects it for 2 reasons:

  • the host header isn't what it expects
  • the content-length isn't what it expects

I tried removing those headers but I can't make the filters work. I tried so many combinations that pasting all of them here won't be very helpful.

Is there a preferred way of capturing a request, removing some headers and then redirect it?

Edit to add some code:

    warp::serve(
        warp::get()
            .and(warp::path("graphiql"))
            .and(juniper_warp::graphiql_filter("/graphql", None))
            .or(warp::path("graphql").and(graphql_filter))
            // .or(reverse_proxy_filter(
            //     "".to_string(),
            //     "https://example.com/".to_string(),
            // ))
            .with(log),
    )
    .run(([127, 0, 0, 1], 8080))
    .await

user -> proxy.com -> example.com

The reverse_proxy_filter redirects, but the Host on the other side rejects the call. These are in different domains. So when example.com receives the request it rejects it because the Host header has the original domain.

Edit: Solved by adding another filter:

.or(warp::any().and(request_filter).and_then(
    |path, query, method, mut headers: Headers, body: Body| {
        headers.remove("Host");
        headers.remove("Content-length");

        proxy_to_and_forward_response(
            "https://example.com".to_string(),
            "".to_string(),
            path,
            query,
            method,
            headers,
            body,
        )
    },
))
Ainestal
  • 1
  • 2
  • What host is it sending and what does the target server expect? What content-length is it sending and what does the target server expect? Flat out omitting those headers is unlikely to help. – kmdreko Oct 11 '22 at 20:40
  • The Host that the server expects is itself. So if the original request goes to example.com and then I redirect it to other.com, this last server expects other.com as Host. The content-length has me a little more intrigued, but when doing some tests with curl turns out that was the problem. – Ainestal Oct 12 '22 at 08:26

0 Answers0