Add CustomHTTPErrors directive

This commit is contained in:
Mr. Erlison 2024-07-29 09:51:05 -03:00
parent 698f15c9e8
commit 1ff37aa7f8
3 changed files with 8 additions and 0 deletions

View file

@ -186,6 +186,8 @@ func TestCrossplaneTemplate(t *testing.T) {
tplConfig.Cfg.UpstreamKeepaliveTimeout = 200
tplConfig.Cfg.UpstreamKeepaliveRequests = 15
tplConfig.Cfg.CustomHTTPErrors = []int{400, 404, 501}
tpl = crossplane.NewTemplate()
tpl.SetMimeFile(mimeFile.Name())
content, err := tpl.Write(tplConfig)

View file

@ -284,6 +284,11 @@ func (c *Template) buildHTTP() {
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{
Directive: "http",
Block: httpBlock,

View file

@ -407,6 +407,7 @@ http {
default "$";
}
# MIGRATED
{{ range $errCode := $cfg.CustomHTTPErrors }}
error_page {{ $errCode }} = @custom_upstream-default-backend_{{ $errCode }};{{ end }}