Skip to content

Commit

Permalink
Add default-type as a configurable for default_type
Browse files Browse the repository at this point in the history
  • Loading branch information
MengqiWu committed Jun 21, 2020
1 parent 6048e63 commit f232a26
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/user-guide/nginx-configuration/configmap.md
Expand Up @@ -183,6 +183,7 @@ The following table shows a configuration option's name, type, and the default v
|[block-user-agents](#block-user-agents)|[]string|""|
|[block-referers](#block-referers)|[]string|""|
|[proxy-ssl-location-only](#proxy-ssl-location-only)|bool|"false"|
|[default-type](#default-type)|string|"text/html"|

## add-headers

Expand Down Expand Up @@ -1084,3 +1085,11 @@ _References:_

Set if proxy-ssl parameters should be applied only on locations and not on servers.
_**default:**_ is disabled

## default-type

Sets the default MIME type of a response.
_**default:**_ text/html

_References:_
[http://nginx.org/en/docs/http/ngx_http_core_module.html#default_type](http://nginx.org/en/docs/http/ngx_http_core_module.html#default_type)
6 changes: 6 additions & 0 deletions internal/ingress/controller/config/config.go
Expand Up @@ -671,6 +671,11 @@ type Configuration struct {
// proxy-ssl-* annotations are applied on on location level only in the nginx.conf file
// Default is that those are applied on server level, too
ProxySSLLocationOnly bool `json:"proxy-ssl-location-only"`

// DefaultType Sets the default MIME type of a response.
// http://nginx.org/en/docs/http/ngx_http_core_module.html#default_type
// Default: text/html
DefaultType string `json:"default-type"`
}

// NewDefault returns the default nginx configuration
Expand Down Expand Up @@ -815,6 +820,7 @@ func NewDefault() Configuration {
NoAuthLocations: "/.well-known/acme-challenge",
GlobalExternalAuth: defGlobalExternalAuth,
ProxySSLLocationOnly: false,
DefaultType: "text/html",
}

if klog.V(5) {
Expand Down
2 changes: 2 additions & 0 deletions internal/ingress/controller/template/configmap_test.go
Expand Up @@ -74,6 +74,7 @@ func TestMergeConfigMapToStruct(t *testing.T) {
"nginx-status-ipv6-whitelist": "::1,2001::/16",
"proxy-add-original-uri-header": "false",
"disable-ipv6-dns": "true",
"default-type": "text/plain",
}
def := config.NewDefault()
def.CustomHTTPErrors = []int{300, 400}
Expand All @@ -97,6 +98,7 @@ func TestMergeConfigMapToStruct(t *testing.T) {
def.ProxyAddOriginalURIHeader = false
def.LuaSharedDicts = defaultLuaSharedDicts
def.DisableIpv6DNS = true
def.DefaultType = "text/plain"

hash, err := hashstructure.Hash(def, &hashstructure.HashOptions{
TagName: "json",
Expand Down
2 changes: 1 addition & 1 deletion rootfs/etc/nginx/template/nginx.tmpl
Expand Up @@ -279,7 +279,7 @@ http {
{{ buildOpentracing $cfg $servers }}

include /etc/nginx/mime.types;
default_type text/html;
default_type {{ $cfg.DefaultType }};

{{ if $cfg.EnableBrotli }}
brotli on;
Expand Down

0 comments on commit f232a26

Please sign in to comment.