github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/docs/proxy/preserve_host_property.md (about)

     1  #### The `preserve_host` property
     2  
     3  When proxying, Janus's default behavior is to set the upstream request's Host header to the hostname of the API's elected upstream from the`upstreams.targets` property. The `preserve_host` field accepts a boolean flag instructing Janus not to do so.
     4  
     5  For example, when the `preserve_host` property is not changed and an API is configured like this:
     6  
     7  ```json
     8  {
     9      "name": "My API",
    10      "hosts": ["service.com"],
    11      "proxy": {
    12          "listen_path": "/foo/*",
    13          "upstreams" : {
    14              "balancing": "roundrobin",
    15              "targets": [
    16                  {"target": "http://my-api.com"}
    17              ]
    18          },
    19          "methods": ["GET"]
    20      }
    21  }
    22  ```
    23  
    24  A possible request from a client to Janus could be:
    25  
    26  ```http
    27  GET / HTTP/1.1
    28  Host: service.com
    29  ```
    30  
    31  Janus would extract the Host header value from the the hostname of the API's elected upstream from the `upstreams.target` field, and would send the following request to your upstream service:
    32  
    33  ```http
    34  GET / HTTP/1.1
    35  Host: my-api.com
    36  ```
    37  
    38  However, by explicitly configuring your API with `preserve_host=true`:
    39  
    40  ```json
    41  {
    42      "name": "My API",
    43      "hosts": ["example.com", "service.com"],
    44      "proxy": {
    45          "listen_path": "/foo/*",
    46          "upstreams" : {
    47              "balancing": "roundrobin",
    48              "targets": [
    49                  {"target": "http://my-api.com"}
    50              ]
    51          },
    52          "methods": ["GET"],
    53          "preserve_host": true
    54      }
    55  }
    56  ```
    57  
    58  And assuming the same request from the client:
    59  
    60  ```http
    61  GET / HTTP/1.1
    62  Host: service.com
    63  ```
    64  
    65  Janus would preserve the Host on the client request and would send the following request to your upstream service:
    66  
    67  ```http
    68  GET / HTTP/1.1
    69  Host: service.com
    70  ```