Skip to content

Commit 31b31c5

Browse files
authored
Merge pull request #43 from Cryptophobia/master
feat(router): Add ability to set X-Request-Start header per app #42
2 parents 94110a2 + 6016a3d commit 31b31c5

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ _Note that Kubernetes annotation maps are all of Go type `map[string]string`. A
230230
| <a name="server-name-hash-max-size"></a>deis-router | deployment | [router.deis.io/nginx.serverNameHashMaxSize](#server-name-hash-max-size) | `"512"` | nginx `server_names_hash_max_size` setting expressed in bytes (no suffix), kilobytes (suffixes `k` and `K`), or megabytes (suffixes `m` and `M`). |
231231
| <a name="server-name-hash-bucket-size"></a>deis-router | deployment | [router.deis.io/nginx.serverNameHashBucketSize](#server-name-hash-bucket-size) | `"64"` | nginx `server_names_hash_bucket_size` setting expressed in bytes (no suffix), kilobytes (suffixes `k` and `K`), or megabytes (suffixes `m` and `M`). |
232232
| <a name="requestIDs"></a>deis-router | deployment | [router.deis.io/nginx.requestIDs](#requestIDs) | `"false"` | Whether to add X-Request-Id and X-Correlation-Id headers. |
233+
| <a name="requestStartHeader"></a>deis-router | deployment | [router.deis.io/nginx.requestStartHeader](#requestStartHeader) | `"false"` | Whether to add `X-Request-Start` headers to all applications' server blocks. The default value for the header is `"t=${msec}"`. To opt-out from setting this header for an app, it is necessary to set `disableRequestStartHeader` annotation on the app service object. |
233234
| <a name="gzip-enabled"></a>deis-router | deployment | [router.deis.io/nginx.gzip.enabled](#gzip-enabled) | `"true"` | Whether to enable gzip compression. |
234235
| <a name="gzip-comp-level"></a>deis-router | deployment | [router.deis.io/nginx.gzip.compLevel](#gzip-comp-level) | `"5"` | nginx `gzip_comp_level` setting. |
235236
| <a name="gzip-disable"></a>deis-router | deployment | [router.deis.io/nginx.gzip.disable](#gzip-disable) | `"msie6"` | nginx `gzip_disable` setting. |
@@ -283,6 +284,7 @@ _Note that Kubernetes annotation maps are all of Go type `map[string]string`. A
283284
| <a name="app-connect-timeout"></a>routable application | service | [router.deis.io/connectTimeout](#app-connect-timeout) | `"30s"` | nginx `proxy_connect_timeout` setting expressed in units `ms`, `s`, `m`, `h`, `d`, `w`, `M`, or `y`. |
284285
| <a name="app-tcp-timeout"></a>routable application | service | [router.deis.io/tcpTimeout](#app-tcp-timeout) | router's `defaultTimeout` | nginx `proxy_send_timeout` and `proxy_read_timeout` settings expressed in units `ms`, `s`, `m`, `h`, `d`, `w`, `M`, or `y`. |
285286
| <a name="app-maintenance"></a>routable application | service | [router.deis.io/maintenance](#app-maintenance) | `"false"` | Whether the app is under maintenance so that all traffic for this app is redirected to a static maintenance page with an error code of `503`. |
287+
| <a name="app-disable-request-start-header"></a>routable application | service | [router.deis.io/disableRequestStartHeader](#app-disable-request-start-header) | N/A | Whether to disable adding the `X-Request-Start` headers to the application when X-Request-Header is set globally. Must be set to `false` in order to opt out of the global behavior for all apps. |
286288
| <a name="ssl-enforce"></a>routable application | service | [router.deis.io/ssl.enforce](#ssl-enforce) | `"false"` | Whether to respond with a 301 for all HTTP requests with a permanent redirect to the HTTPS equivalent address. |
287289
| <a name="app-nginx-proxy-buffers-enabled"></a>routable application | service | [router.deis.io/nginx.proxyBuffers.enabled](#app-nginx-proxy-buffers-enabled) | `"false"` | Whether to enabled proxy buffering. This can be used to override the same option set globally on the router. |
288290
| <a name="app-nginx-proxy-buffers-number"></a>routable application | service | [router.deis.io/nginx.proxyBuffers.number](#app-nginx-proxy-buffers-number) | `"8"` | `number` argument to the nginx `proxy_buffers` directive. This can be used to override the same option set globally on the router. |

model/model.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type RouterConfig struct {
6262
DefaultAppName string `key:"defaultAppName"`
6363
DefaultServiceEnabled bool `key:"defaultServiceEnabled" constraint:"(?i)^(true|false)$"`
6464
RequestIDs bool `key:"requestIDs" constraint:"(?i)^(true|false)$"`
65+
RequestStartHeader bool `key:"requestStartHeader" constraint:"(?i)^(true|false)$"`
6566
SSLConfig *SSLConfig `key:"ssl"`
6667
AppConfigs []*AppConfig
6768
BuilderConfig *BuilderConfig
@@ -99,6 +100,7 @@ func newRouterConfig() (*RouterConfig, error) {
99100
EnableRegexDomains: false,
100101
LoadModsecurityModule: false,
101102
RequestIDs: false,
103+
RequestStartHeader: false,
102104
SSLConfig: newSSLConfig(),
103105
DefaultServiceEnabled: false,
104106
DefaultAppName: "",
@@ -139,23 +141,24 @@ func newGzipConfig() *GzipConfig {
139141

140142
// AppConfig encapsulates the configuration for all routes to a single back end.
141143
type AppConfig struct {
142-
Name string
143-
Domains []string `key:"domains" constraint:"(?i)^((([a-z0-9]+(-*[a-z0-9]+)*)|((\\*\\.)?[a-z0-9]+(-*[a-z0-9]+)*\\.)+[a-z0-9]+(-*[a-z0-9]+)+)(\\s*,\\s*)?)+$"`
144-
RegexDomain string `key:"regexDomain"`
145-
Whitelist []string `key:"whitelist" 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*)?)+$"`
146-
ConnectTimeout string `key:"connectTimeout" constraint:"^[1-9]\\d*(ms|[smhdwMy])?$"`
147-
TCPTimeout string `key:"tcpTimeout" constraint:"^[1-9]\\d*(ms|[smhdwMy])?$"`
148-
ServiceIP string
149-
CertMappings map[string]string `key:"certificates" constraint:"(?i)^((([a-z0-9]+(-*[a-z0-9]+)*)|((\\*\\.)?[a-z0-9]+(-*[a-z0-9]+)*\\.)+[a-z0-9]+(-*[a-z0-9]+)+):([a-z0-9]+(-*[a-z0-9]+)*)(\\s*,\\s*)?)+$"`
150-
Certificates map[string]*Certificate
151-
Available bool
152-
Maintenance bool `key:"maintenance" constraint:"(?i)^(true|false)$"`
153-
ReferrerPolicy string `key:"referrerPolicy" constraint:"^(no-referrer|no-referrer-when-downgrade|origin|origin-when-cross-origin|same-origin|strict-origin|strict-origin-when-cross-origin|unsafe-url|none)$"`
154-
SSLConfig *SSLConfig `key:"ssl"`
155-
Nginx *NginxAppConfig `key:"nginx"`
156-
ProxyLocations []string `key:"proxyLocations"`
157-
ProxyDomain string `key:"proxyDomain"`
158-
Locations []*Location
144+
Name string
145+
Domains []string `key:"domains" constraint:"(?i)^((([a-z0-9]+(-*[a-z0-9]+)*)|((\\*\\.)?[a-z0-9]+(-*[a-z0-9]+)*\\.)+[a-z0-9]+(-*[a-z0-9]+)+)(\\s*,\\s*)?)+$"`
146+
RegexDomain string `key:"regexDomain"`
147+
Whitelist []string `key:"whitelist" 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*)?)+$"`
148+
ConnectTimeout string `key:"connectTimeout" constraint:"^[1-9]\\d*(ms|[smhdwMy])?$"`
149+
TCPTimeout string `key:"tcpTimeout" constraint:"^[1-9]\\d*(ms|[smhdwMy])?$"`
150+
ServiceIP string
151+
CertMappings map[string]string `key:"certificates" constraint:"(?i)^((([a-z0-9]+(-*[a-z0-9]+)*)|((\\*\\.)?[a-z0-9]+(-*[a-z0-9]+)*\\.)+[a-z0-9]+(-*[a-z0-9]+)+):([a-z0-9]+(-*[a-z0-9]+)*)(\\s*,\\s*)?)+$"`
152+
Certificates map[string]*Certificate
153+
Available bool
154+
Maintenance bool `key:"maintenance" constraint:"(?i)^(true|false)$"`
155+
DisableRequestStartHeader bool `key:"disableRequestStartHeader" constraint:"(?i)^(true|false)$"`
156+
ReferrerPolicy string `key:"referrerPolicy" constraint:"^(no-referrer|no-referrer-when-downgrade|origin|origin-when-cross-origin|same-origin|strict-origin|strict-origin-when-cross-origin|unsafe-url|none)$"`
157+
SSLConfig *SSLConfig `key:"ssl"`
158+
Nginx *NginxAppConfig `key:"nginx"`
159+
ProxyLocations []string `key:"proxyLocations"`
160+
ProxyDomain string `key:"proxyDomain"`
161+
Locations []*Location
159162
}
160163

161164
// Location represents a location block inside a back end server block.

nginx/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ http {
308308
proxy_set_header X-Request-Id $request_id;
309309
proxy_set_header X-Correlation-Id $correlation_id;
310310
{{ end }}
311+
{{ if and $routerConfig.RequestStartHeader (not $appConfig.DisableRequestStartHeader) }}
312+
proxy_set_header X-Request-Start "t=${msec}";
313+
{{ end }}
311314
312315
{{ if or $enforceSecure $location.App.SSLConfig.Enforce }}if ($access_scheme !~* "^https|wss$") {
313316
return 301 $uri_scheme://$host$request_uri;

0 commit comments

Comments
 (0)