From ee9d9d1b7ae50d6c32f12e7a45348f58f40e9ee9 Mon Sep 17 00:00:00 2001 From: zitudu Date: Thu, 17 Aug 2023 15:35:18 +0800 Subject: [PATCH] Remove unused helper fieldValueComponet --- .../ingress/controller/template/template.go | 14 ------------- .../controller/template/template_test.go | 21 ------------------- rootfs/etc/nginx/template/nginx.tmpl | 10 ++++----- 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 29340a0cb..147455771 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -281,14 +281,9 @@ var ( "shouldLoadAuthDigestModule": shouldLoadAuthDigestModule, "buildServerName": buildServerName, "buildCorsOriginRegex": buildCorsOriginRegex, - "fieldValueComponet": fieldValueComponet, } ) -var ( - headerFieldValueTokenChars = regexp.MustCompile("^[!#$%&'*+.^_`|~0-9A-Za-z-]+$") -) - // escapeLiteralDollar will replace the $ character with ${literal_dollar} // which is made to work via the following configuration in the http section of // the template: @@ -1859,12 +1854,3 @@ func buildCorsOriginRegex(corsOrigins []string) string { originsRegex = originsRegex + ")$ ) { set $cors 'true'; }" return originsRegex } - -// Token containing character other than tchar must be quoted using -// double-quote marks (section 3.2.6 of RFC 7230). -func fieldValueComponet(s string) string { - if headerFieldValueTokenChars.MatchString(s) { - return s - } - return fmt.Sprintf("%q", s) -} diff --git a/internal/ingress/controller/template/template_test.go b/internal/ingress/controller/template/template_test.go index c8c6cb11d..a2c3b8299 100644 --- a/internal/ingress/controller/template/template_test.go +++ b/internal/ingress/controller/template/template_test.go @@ -2237,24 +2237,3 @@ func TestCleanConf(t *testing.T) { t.Errorf("cleanConf result don't match with expected: %s", diff) } } - -func TestFieldValueComponet(t *testing.T) { - testCases := map[string]struct { - input string - expect string - }{ - "empty": {"", `""`}, - "spaces": {" ", `" "`}, - "ipv4": {"1.2.3.4", `1.2.3.4`}, - "ipv6": {"[::1]", `"[::1]"`}, - "obfuscated identifier": {"_hidden", `_hidden`}, - "ipv4 port": {"1.2.3.4:80", `"1.2.3.4:80"`}, - "domain": {"example.com", `example.com`}, - "http schema": {"http", `http`}, - } - for name, tc := range testCases { - if comp := fieldValueComponet(tc.input); comp != tc.expect { - t.Errorf("%v: expected '%v' but returned '%v'", name, tc.expect, comp) - } - } -} diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index df2746ad0..b7f6a6a22 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -456,7 +456,7 @@ http { {{ if $cfg.EnableForwardedRFC7239 }} # Enabled standard forwarded (RFC 7239). - # Used to declare constant variables. + # Used to declare variables as constants. map $nginx_version $nginx_constant { default ''; } @@ -476,9 +476,9 @@ http { default "for=unknown"; } {{ else }} - # Set proxy_forwarded_rfc2379_for as a constant string. + # Set proxy_forwarded_rfc2379_for as a obfuscated string. map $nginx_constant $proxy_forwarded_rfc2379_for { - default {{ $cfg.ForwardedRFC7239For | fieldValueComponet | printf "for=%s" | quote }}; + default "for={{ $cfg.ForwardedRFC7239For }}"; } {{ end }} @@ -496,9 +496,9 @@ http { default "by=unknown"; } {{ else }} - # Set proxy_forwarded_rfc2379_by as a constant string. + # Set proxy_forwarded_rfc2379_by as a static obfuscated string. map $nginx_constant $proxy_forwarded_rfc2379_by { - default {{ $cfg.ForwardedRFC7239By | fieldValueComponet | printf "by=%s" | quote }}; + default "by={{ $cfg.ForwardedRFC7239By }}"; } {{ end }}