Allow gzip compress level to be controlled via ConfigMap

This commit is contained in:
Jason Stangroome 2018-07-09 10:30:59 +10:00
parent c9ca9ffeaa
commit 8e06afbb45
4 changed files with 12 additions and 1 deletions

View file

@ -87,6 +87,7 @@ The following table shows a configuration option's name, type, and the default v
|[brotli-level](#brotli-level)|int|4| |[brotli-level](#brotli-level)|int|4|
|[brotli-types](#brotli-types)|string|"application/xml+rss application/atom+xml application/javascript application/x-javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component"| |[brotli-types](#brotli-types)|string|"application/xml+rss application/atom+xml application/javascript application/x-javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component"|
|[use-http2](#use-http2)|bool|"true"| |[use-http2](#use-http2)|bool|"true"|
|[gzip-level](#gzip-level)|int|5|
|[gzip-types](#gzip-types)|string|"application/atom+xml application/javascript application/x-javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component"| |[gzip-types](#gzip-types)|string|"application/atom+xml application/javascript application/x-javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component"|
|[worker-processes](#worker-processes)|string|`<Number of CPUs>`| |[worker-processes](#worker-processes)|string|`<Number of CPUs>`|
|[worker-cpu-affinity](#worker-cpu-affinity)|string|""| |[worker-cpu-affinity](#worker-cpu-affinity)|string|""|
@ -486,6 +487,10 @@ _**default:**_ `application/xml+rss application/atom+xml application/javascript
Enables or disables [HTTP/2](http://nginx.org/en/docs/http/ngx_http_v2_module.html) support in secure connections. Enables or disables [HTTP/2](http://nginx.org/en/docs/http/ngx_http_v2_module.html) support in secure connections.
## gzip-level
Sets the gzip Compression Level that will be used. _**default:**_ 5
## gzip-types ## gzip-types
Sets the MIME types in addition to "text/html" to compress. The special value "\*" matches any MIME type. Responses with the "text/html" type are always compressed if `use-gzip` is enabled. Sets the MIME types in addition to "text/html" to compress. The special value "\*" matches any MIME type. Responses with the "text/html" type are always compressed if `use-gzip` is enabled.

View file

@ -350,6 +350,9 @@ type Configuration struct {
// Default: true // Default: true
UseHTTP2 bool `json:"use-http2,omitempty"` UseHTTP2 bool `json:"use-http2,omitempty"`
// gzip Compression Level that will be used
GzipLevel int `json:"gzip-level,omitempty"`
// MIME types in addition to "text/html" to compress. The special value “*” matches any MIME type. // MIME types in addition to "text/html" to compress. The special value “*” matches any MIME type.
// Responses with the “text/html” type are always compressed if UseGzip is enabled // Responses with the “text/html” type are always compressed if UseGzip is enabled
GzipTypes string `json:"gzip-types,omitempty"` GzipTypes string `json:"gzip-types,omitempty"`
@ -553,6 +556,7 @@ func NewDefault() Configuration {
HSTSMaxAge: hstsMaxAge, HSTSMaxAge: hstsMaxAge,
HSTSPreload: false, HSTSPreload: false,
IgnoreInvalidHeaders: true, IgnoreInvalidHeaders: true,
GzipLevel: 5,
GzipTypes: gzipTypes, GzipTypes: gzipTypes,
KeepAlive: 75, KeepAlive: 75,
KeepAliveRequests: 100, KeepAliveRequests: 100,

View file

@ -63,6 +63,7 @@ func TestMergeConfigMapToStruct(t *testing.T) {
"error-log-path": "/var/log/test/error.log", "error-log-path": "/var/log/test/error.log",
"use-gzip": "true", "use-gzip": "true",
"enable-dynamic-tls-records": "false", "enable-dynamic-tls-records": "false",
"gzip-level": "9",
"gzip-types": "text/html", "gzip-types": "text/html",
"proxy-real-ip-cidr": "1.1.1.1/8,2.2.2.2/24", "proxy-real-ip-cidr": "1.1.1.1/8,2.2.2.2/24",
"bind-address": "1.1.1.1,2.2.2.2,3.3.3,2001:db8:a0b:12f0::1,3731:54:65fe:2::a7,33:33:33::33::33", "bind-address": "1.1.1.1,2.2.2.2,3.3.3,2001:db8:a0b:12f0::1,3731:54:65fe:2::a7,33:33:33::33::33",
@ -81,6 +82,7 @@ func TestMergeConfigMapToStruct(t *testing.T) {
def.ProxySendTimeout = 2 def.ProxySendTimeout = 2
def.EnableDynamicTLSRecords = false def.EnableDynamicTLSRecords = false
def.UseProxyProtocol = true def.UseProxyProtocol = true
def.GzipLevel = 9
def.GzipTypes = "text/html" def.GzipTypes = "text/html"
def.ProxyRealIPCIDR = []string{"1.1.1.1/8", "2.2.2.2/24"} def.ProxyRealIPCIDR = []string{"1.1.1.1/8", "2.2.2.2/24"}
def.BindAddressIpv4 = []string{"1.1.1.1", "2.2.2.2"} def.BindAddressIpv4 = []string{"1.1.1.1", "2.2.2.2"}

View file

@ -169,7 +169,7 @@ http {
{{ if $cfg.UseGzip }} {{ if $cfg.UseGzip }}
gzip on; gzip on;
gzip_comp_level 5; gzip_comp_level {{ $cfg.GzipLevel }};
gzip_http_version 1.1; gzip_http_version 1.1;
gzip_min_length 256; gzip_min_length 256;
gzip_types {{ $cfg.GzipTypes }}; gzip_types {{ $cfg.GzipTypes }};