Set request and response headers

This commit is contained in:
Donal McBreen
2024-07-31 13:55:58 +01:00
committed by Donal McBreen
parent fe0c656de5
commit 55756fa6f3
3 changed files with 17 additions and 2 deletions

View File

@@ -34,7 +34,6 @@ class Kamal::Commands::Proxy < Kamal::Commands::Base
end
def deploy(service, target:)
optionize({ target: target })
docker :exec, container_name, "kamal-proxy", :deploy, service, *optionize({ target: target }), *proxy_config.deploy_command_args
end

View File

@@ -93,6 +93,19 @@ proxy:
max_response_body: 0
memory: 2_000_000
# Logging
#
# Configure request logging for the proxy
# You can specify request and response headers to log.
# By default, Cache-Control and Last-Modified request headers are logged
logging:
request_headers:
- Cache-Control
- X-Forwarded-Proto
response_headers:
- X-Request-ID
- X-Request-Start
# Forward headers
#
# Whether to forward the X-Forwarded-For and X-Forwarded-Proto headers (defaults to false)

View File

@@ -4,6 +4,7 @@ class Kamal::Configuration::Proxy
DEFAULT_HTTP_PORT = 80
DEFAULT_HTTPS_PORT = 443
DEFAULT_IMAGE = "basecamp/kamal-proxy:latest"
DEFAULT_LOG_REQUEST_HEADERS = [ "Cache-Control", "Last-Modified" ]
delegate :argumentize, :optionize, to: Kamal::Utils
@@ -50,7 +51,9 @@ class Kamal::Configuration::Proxy
"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"),
"forward-headers": proxy_config.dig("forward_headers")
"forward-headers": proxy_config.dig("forward_headers"),
"log-request-header": proxy_config.dig("logging", "request_headers") || DEFAULT_LOG_REQUEST_HEADERS,
"log-response-header": proxy_config.dig("logging", "response_headers")
}.compact
end