Add CustomHTTPErrors directive
This commit is contained in:
parent
698f15c9e8
commit
1ff37aa7f8
3 changed files with 8 additions and 0 deletions
|
@ -186,6 +186,8 @@ func TestCrossplaneTemplate(t *testing.T) {
|
||||||
tplConfig.Cfg.UpstreamKeepaliveTimeout = 200
|
tplConfig.Cfg.UpstreamKeepaliveTimeout = 200
|
||||||
tplConfig.Cfg.UpstreamKeepaliveRequests = 15
|
tplConfig.Cfg.UpstreamKeepaliveRequests = 15
|
||||||
|
|
||||||
|
tplConfig.Cfg.CustomHTTPErrors = []int{400, 404, 501}
|
||||||
|
|
||||||
tpl = crossplane.NewTemplate()
|
tpl = crossplane.NewTemplate()
|
||||||
tpl.SetMimeFile(mimeFile.Name())
|
tpl.SetMimeFile(mimeFile.Name())
|
||||||
content, err := tpl.Write(tplConfig)
|
content, err := tpl.Write(tplConfig)
|
||||||
|
|
|
@ -284,6 +284,11 @@ func (c *Template) buildHTTP() {
|
||||||
httpBlock = append(httpBlock, buildMapDirective("$http_referer", "$block_ref", refDirectives))
|
httpBlock = append(httpBlock, buildMapDirective("$http_referer", "$block_ref", refDirectives))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, v := range cfg.CustomHTTPErrors {
|
||||||
|
httpBlock = append(httpBlock, buildDirective("error_page", v,
|
||||||
|
fmt.Sprintf("@custom_upstream-default-backend_%d", v)))
|
||||||
|
}
|
||||||
|
|
||||||
c.config.Parsed = append(c.config.Parsed, &ngx_crossplane.Directive{
|
c.config.Parsed = append(c.config.Parsed, &ngx_crossplane.Directive{
|
||||||
Directive: "http",
|
Directive: "http",
|
||||||
Block: httpBlock,
|
Block: httpBlock,
|
||||||
|
|
|
@ -407,6 +407,7 @@ http {
|
||||||
default "$";
|
default "$";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# MIGRATED
|
||||||
{{ range $errCode := $cfg.CustomHTTPErrors }}
|
{{ range $errCode := $cfg.CustomHTTPErrors }}
|
||||||
error_page {{ $errCode }} = @custom_upstream-default-backend_{{ $errCode }};{{ end }}
|
error_page {{ $errCode }} = @custom_upstream-default-backend_{{ $errCode }};{{ end }}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue