Remove unused helper fieldValueComponet
This commit is contained in:
parent
b6f83d55b8
commit
ee9d9d1b7a
3 changed files with 5 additions and 40 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 }}
|
||||
|
||||
|
|
Loading…
Reference in a new issue