Mirrored request with host rewrite has wrong Host header
- Dominant language
- C++
- Stars
- 28.9k
- Forks
- 5.6k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 430
Description
*Description*:
I'm currently trying to use `request_mirror_policy` in a route that is also using `auto_host_rewrite`.
The problem are the `host/:authority` headers in the mirrored request is giving me weird results...
*Repro steps*:
I created a simplified version of my setup in this [gist](https://gist.github.com/Brunomachadob/33c53e0c3557283eb2e802cc2699fc39) including a full log of execution
```bash
docker-compose up --build
```
```bash
curl localhost:5000/any/host_rewrite
```
Mock server logs 2 requests
```bash
# The actual request
mockserver_1 | {
mockserver_1 | "method" : "GET",
mockserver_1 | "path" : "/any/host_rewrite",
mockserver_1 | "headers" : [ {
mockserver_1 | "name" : "host",
mockserver_1 | "values" : [ "api" ] # successfully rewritten
mockserver_1 | }, {
....
```
```bash
# The mirror request
mockserver_1 | {
mockserver_1 | "method" : "GET",
mockserver_1 | "path" : "/any/host_rewrite",
mockserver_1 | "headers" : [ {
mockserver_1 | "name" : "host",
mockserver_1 | "values" : [ "localhost-shadow:5000" ] # Why localhost?
mockserver_1 | }, {
....
```
Calling again...
```bash
curl localhost:5000/any/host_rewrite
```
Mock server logs 2 requests
```bash
# The actual request
mockserver_1 | {
mockserver_1 | "method" : "GET",
mockserver_1 | "path" : "/any/host_rewrite",
mockserver_1 | "headers" : [ {
mockserver_1 | "name" : "host",
mockserver_1 | "values" : [ "api" ] # successfully rewritten
mockserver_1 | }, {
```
```bash
# The mirrored request
mockserver_1 | {
mockserver_1 | "method" : "GET",
mockserver_1 | "path" : "/any/host_rewrite",
mockserver_1 | "headers" : [ {
mockserver_1 | "name" : "host",
mockserver_1 | "values" : [ "api-shadow" ] # successfully rewritten
```
From now on it's always successfully rewritten, until I restart the containers and the same thing happen. Maybe this is some caching problem in the host resolution?
*Tested versions*
`envoyproxy/envoy:v1.10.0`
`envoyproxy/envoy-dev:daeb9850dbcd78da21a2e8ff9854564830cefb19 # 1.13.0-dev`
*Additional question*
As you can see in my `envoy.yaml` I want to mirror the request to another cluster with another domain (I'm migrating one feature from a monolith to a microservice).
So in my case the real request is going to `api`, and the mirror request is going to another cluster called `api-mirror`. In this case, shouldn't the request mirror get the `host=api-mirror-shadow`?
The [documentation](https://www.envoyproxy.io/docs/envoy/latest/api-v2/api/v2/route/route.proto#envoy-api-msg-route-routeaction-requestmirrorpolicy) is not really clear (at least to me) which cluster is going to be used when rewriting, the mirror cluster or the original one?
Thanks for the help!
Contributor guide
Assessment
This issue has not been assessed yet.