diff --git a/sdk/config_helpers.go b/sdk/config_helpers.go index fffddead7..3aae0e197 100644 --- a/sdk/config_helpers.go +++ b/sdk/config_helpers.go @@ -661,7 +661,7 @@ func parseServerHost(parent *crossplane.Directive) string { case "listen": host, port, err := net.SplitHostPort(dir.Args[0]) if err == nil { - if host != "*" && host != "::" { + if host != "*" && host != "::" && host != "" { serverName = host } listenPort = port @@ -691,7 +691,11 @@ func isPort(value string) bool { func parseLocationPath(location *crossplane.Directive) string { path := "/" if len(location.Args) > 0 { - path = location.Args[0] + if location.Args[0] != "=" { + path = location.Args[0] + } else { + path = location.Args[1] + } } return path } diff --git a/sdk/config_helpers_test.go b/sdk/config_helpers_test.go index dce4acc6b..0e82df22c 100644 --- a/sdk/config_helpers_test.go +++ b/sdk/config_helpers_test.go @@ -867,6 +867,54 @@ server { deny all; } } +`, + }, + { + plus: []string{ + "http://127.0.0.1:80/api/", + }, + conf: ` +server { + listen 127.0.0.1; + server_name _; + location = /api/ { + api write=on; + allow 127.0.0.1; + deny all; + } +} +`, + }, + { + plus: []string{ + "http://localhost:80/api/", + }, + conf: ` +server { + listen 80; + server_name _; + location = /api/ { + api write=on; + allow 127.0.0.1; + deny all; + } +} +`, + }, + { + plus: []string{ + "http://localhost:80/api/", + }, + conf: ` +server { + listen :80; + server_name _; + location = /api/ { + api write=on; + allow 127.0.0.1; + deny all; + } +} `, }, { @@ -939,6 +987,72 @@ server { } `, }, + { + oss: []string{ + "http://localhost:80/stub_status", + }, + conf: ` + server { + server_name localhost; + listen :80; + + error_page 500 502 503 504 /50x.html; + # ssl_certificate /usr/local/nginx/conf/cert.pem; + + location / { + root /tmp/testdata/foo; + } + + location /stub_status { + stub_status; + } + } + `, + }, + { + oss: []string{ + "http://localhost:80/stub_status", + }, + conf: ` + server { + server_name localhost; + listen 80; + + error_page 500 502 503 504 /50x.html; + # ssl_certificate /usr/local/nginx/conf/cert.pem; + + location / { + root /tmp/testdata/foo; + } + + location /stub_status { + stub_status; + } + } + `, + }, + { + oss: []string{ + "http://localhost:80/stub_status", + }, + conf: ` + server { + server_name localhost; + listen 80; + + error_page 500 502 503 504 /50x.html; + # ssl_certificate /usr/local/nginx/conf/cert.pem; + + location / { + root /tmp/testdata/foo; + } + + location = /stub_status { + stub_status; + } + } + `, + }, } { f, err := os.CreateTemp(tmpDir, "conf") assert.NoError(t, err) diff --git a/test/integration/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go b/test/integration/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go index fffddead7..3aae0e197 100644 --- a/test/integration/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go +++ b/test/integration/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go @@ -661,7 +661,7 @@ func parseServerHost(parent *crossplane.Directive) string { case "listen": host, port, err := net.SplitHostPort(dir.Args[0]) if err == nil { - if host != "*" && host != "::" { + if host != "*" && host != "::" && host != "" { serverName = host } listenPort = port @@ -691,7 +691,11 @@ func isPort(value string) bool { func parseLocationPath(location *crossplane.Directive) string { path := "/" if len(location.Args) > 0 { - path = location.Args[0] + if location.Args[0] != "=" { + path = location.Args[0] + } else { + path = location.Args[1] + } } return path } diff --git a/test/performance/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go b/test/performance/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go index fffddead7..3aae0e197 100644 --- a/test/performance/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go +++ b/test/performance/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go @@ -661,7 +661,7 @@ func parseServerHost(parent *crossplane.Directive) string { case "listen": host, port, err := net.SplitHostPort(dir.Args[0]) if err == nil { - if host != "*" && host != "::" { + if host != "*" && host != "::" && host != "" { serverName = host } listenPort = port @@ -691,7 +691,11 @@ func isPort(value string) bool { func parseLocationPath(location *crossplane.Directive) string { path := "/" if len(location.Args) > 0 { - path = location.Args[0] + if location.Args[0] != "=" { + path = location.Args[0] + } else { + path = location.Args[1] + } } return path } diff --git a/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go b/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go index fffddead7..3aae0e197 100644 --- a/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go +++ b/vendor/github.com/nginx/agent/sdk/v2/config_helpers.go @@ -661,7 +661,7 @@ func parseServerHost(parent *crossplane.Directive) string { case "listen": host, port, err := net.SplitHostPort(dir.Args[0]) if err == nil { - if host != "*" && host != "::" { + if host != "*" && host != "::" && host != "" { serverName = host } listenPort = port @@ -691,7 +691,11 @@ func isPort(value string) bool { func parseLocationPath(location *crossplane.Directive) string { path := "/" if len(location.Args) > 0 { - path = location.Args[0] + if location.Args[0] != "=" { + path = location.Args[0] + } else { + path = location.Args[1] + } } return path }