Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.

Commit 151916e

Browse files
author
Rob Holland
committed
feat(nginx): Allow sending nginx X-Request-Id and X-Correlation-Id headers.
1 parent e38a69b commit 151916e

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

model/model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type RouterConfig struct {
4949
EnforceWhitelists bool `key:"enforceWhitelists" constraint:"(?i)^(true|false)$"`
5050
DefaultWhitelist []string `key:"defaultWhitelist" constraint:"^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\\/([0-9]|[1-2][0-9]|3[0-2]))?(\\s*,\\s*)?)+$"`
5151
WhitelistMode string `key:"whitelistMode" constraint:"^(extend|override)$"`
52+
RequestIDs bool `key:"RequestIDs" constraint:"(?i)^(true|false)$"`
5253
SSLConfig *SSLConfig `key:"ssl"`
5354
AppConfigs []*AppConfig
5455
BuilderConfig *BuilderConfig
@@ -71,6 +72,7 @@ func newRouterConfig() *RouterConfig {
7172
UseProxyProtocol: false,
7273
EnforceWhitelists: false,
7374
WhitelistMode: "extend",
75+
RequestIDs: false,
7476
SSLConfig: newSSLConfig(),
7577
HTTP2Enabled: true,
7678
}

nginx/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ http {
108108
}
109109
{{ end }}
110110
111+
{{ if $routerConfig.RequestIDs }}
112+
map $http_x_correlation_id $correlation_id {
113+
default "$http_x_correlation_id,$request_id";
114+
'' $request_id;
115+
}
116+
{{ end }}
117+
111118
{{/* Since HSTS headers are not permitted on HTTP requests, 301 redirects to HTTPS resources are also necessary. */}}
112119
{{/* This means we force HTTPS if HSTS is enabled. */}}
113120
{{ $enforceHTTPS := or $sslConfig.Enforce $hstsConfig.Enabled }}
@@ -188,6 +195,11 @@ http {
188195
vhost_traffic_status_filter_by_set_key {{ $appConfig.Name }} application::*;
189196
190197
location / {
198+
{{ if $routerConfig.RequestIDs }}
199+
add_header X-Request-Id $request_id always;
200+
add_header X-Correlation-Id $correlation_id always;
201+
{{end}}
202+
191203
{{ if $appConfig.Maintenance }}return 503;{{ else if $appConfig.Available }}proxy_buffering off;
192204
proxy_set_header Host $host;
193205
proxy_set_header X-Forwarded-For $remote_addr;
@@ -200,6 +212,10 @@ http {
200212
proxy_http_version 1.1;
201213
proxy_set_header Upgrade $http_upgrade;
202214
proxy_set_header Connection $connection_upgrade;
215+
{{ if $routerConfig.RequestIDs }}
216+
proxy_set_header X-Request-Id $request_id;
217+
proxy_set_header X-Correlation-Id $correlation_id;
218+
{{ end }}
203219
204220
{{ if or $enforceHTTPS $appConfig.SSLConfig.Enforce }}if ($access_scheme != "https") {
205221
return 301 https://$host$request_uri;

0 commit comments

Comments
 (0)