From d891eb91e406ec4a9fb4a74625a22ad10d2c13e0 Mon Sep 17 00:00:00 2001 From: Donal McBreen Date: Wed, 31 Jul 2024 10:44:48 +0100 Subject: [PATCH] Add forward headers support --- lib/kamal/configuration/docs/proxy.yml | 7 +++++++ lib/kamal/configuration/proxy.rb | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/kamal/configuration/docs/proxy.yml b/lib/kamal/configuration/docs/proxy.yml index dbf47a2b..0c541c51 100644 --- a/lib/kamal/configuration/docs/proxy.yml +++ b/lib/kamal/configuration/docs/proxy.yml @@ -91,3 +91,10 @@ proxy: max_request_body: 40_000_000 max_response_body: 0 memory: 2_000_000 + + # Forward headers + # + # Whether to forward the X-Forwarded-For and X-Forwarded-Proto headers (defaults to false) + # + # If you are behind a trusted proxy, you can set this to true to forward the headers. + forward_headers: true diff --git a/lib/kamal/configuration/proxy.rb b/lib/kamal/configuration/proxy.rb index 732195d3..df409d04 100644 --- a/lib/kamal/configuration/proxy.rb +++ b/lib/kamal/configuration/proxy.rb @@ -48,7 +48,8 @@ class Kamal::Configuration::Proxy "buffer": proxy_config.fetch("buffer", { enabled: true }).fetch("enabled", true), "buffer-memory": proxy_config.dig("buffer", "memory"), "max-request-body": proxy_config.dig("buffer", "max_request_body"), - "max-response-body": proxy_config.dig("buffer", "max_response_body") + "max-response-body": proxy_config.dig("buffer", "max_response_body"), + "forward-headers": proxy_config.dig("forward_headers") }.compact end