📗
Janus Manual
  • Introduction
  • Installation
    • Docker
  • Quick Start
    • Authenticating
    • Add an endpoint
    • Modify (Update/Delete) an endpoint
    • Add Plugins
    • Authentication
    • Adding your API - File System
  • Clustering/HA
  • Proxy Reference
    • Terminology
    • Overview
    • Routing capabilities
    • Load Balacing
    • Request Host header
      • Using wildcard hostnames
      • The preserve_host property
    • Request URI
      • The strip_path property
      • The append_path property
    • Request HTTP method
    • Routing priorities
    • Conclusion
  • Plugins
    • Basic
    • Organization
    • Body Limit
    • Circuit Breaker
    • Compression
    • CORS
    • OAuth
    • Rate Limit
    • Request Transformer
    • Response Transformer
    • Retry
  • Auth
    • OAuth 2.0
  • Misc
    • Health Checks
    • Monitoring
    • Tracing
  • Known Issues
    • Stale HTTP Keep-Alive
  • Upgrade Notes
    • 2.x to 3.x
    • 3.6.x to 3.7.x
Powered by GitBook
On this page

Was this helpful?

  1. Proxy Reference
  2. Request Host header

The preserve_host property

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 theupstreams.targets property. The preserve_host field accepts a boolean flag instructing Janus not to do so.

For example, when the preserve_host property is not changed and an API is configured like this:

{
    "name": "My API",
    "hosts": ["service.com"],
    "proxy": {
        "listen_path": "/foo/*",
        "upstreams" : {
            "balancing": "roundrobin",
            "targets": [
                {"target": "http://my-api.com"}
            ]
        },
        "methods": ["GET"]
    }
}

A possible request from a client to Janus could be:

GET / HTTP/1.1
Host: service.com

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:

GET / HTTP/1.1
Host: my-api.com

However, by explicitly configuring your API with preserve_host=true:

{
    "name": "My API",
    "hosts": ["example.com", "service.com"],
    "proxy": {
        "listen_path": "/foo/*",
        "upstreams" : {
            "balancing": "roundrobin",
            "targets": [
                {"target": "http://my-api.com"}
            ]
        },
        "methods": ["GET"],
        "preserve_host": true
    }
}

And assuming the same request from the client:

GET / HTTP/1.1
Host: service.com

Janus would preserve the Host on the client request and would send the following request to your upstream service:

GET / HTTP/1.1
Host: service.com
PreviousUsing wildcard hostnamesNextRequest URI

Last updated 4 years ago

Was this helpful?