Remove variables with $ before feeding into url.Parse
Signed-off-by: Gerald Pape <gerald@giantswarm.io>
This commit is contained in:
parent
057c1b26fb
commit
41f6f8c9c1
3 changed files with 25 additions and 3 deletions
|
@ -945,6 +945,9 @@ The mirror backend can be set by applying:
|
||||||
nginx.ingress.kubernetes.io/mirror-target: https://test.env.com/$request_uri
|
nginx.ingress.kubernetes.io/mirror-target: https://test.env.com/$request_uri
|
||||||
```
|
```
|
||||||
|
|
||||||
|
!!! attention
|
||||||
|
When `nginx.ingress.kubernetes.io/mirror-host` is not defined, the `Host` header value is extracted from `nginx.ingress.kubernetes.io/mirror-target`, which is processed using [`url.Parse`](https://pkg.go.dev/net/url#Parse). However, if there is no `/` separator, `url.Parse` is unable to distinguish between additional path variables and the port number in the `mirror-target` value.
|
||||||
|
|
||||||
By default the request-body is sent to the mirror backend, but can be turned off by applying:
|
By default the request-body is sent to the mirror backend, but can be turned off by applying:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|
|
@ -93,12 +93,13 @@ func (a mirror) Parse(ing *networking.Ingress) (interface{}, error) {
|
||||||
config.Host, err = parser.GetStringAnnotation("mirror-host", ing)
|
config.Host, err = parser.GetStringAnnotation("mirror-host", ing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if config.Target != "" {
|
if config.Target != "" {
|
||||||
url, err := parser.StringToURL(config.Target)
|
target := strings.Split(config.Target, "$")
|
||||||
|
|
||||||
|
url, err := parser.StringToURL(target[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
config.Host = ""
|
config.Host = ""
|
||||||
} else {
|
} else {
|
||||||
hostname := strings.Split(url.Hostname(), "$")
|
config.Host = url.Hostname()
|
||||||
config.Host = hostname[0]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,24 @@ func TestParse(t *testing.T) {
|
||||||
Target: "https://test.env.com/$request_uri",
|
Target: "https://test.env.com/$request_uri",
|
||||||
Host: "test.env.com",
|
Host: "test.env.com",
|
||||||
}},
|
}},
|
||||||
|
{map[string]string{backendURL: "https://test.env.com$request_uri"}, &Config{
|
||||||
|
Source: ngxURI,
|
||||||
|
RequestBody: "on",
|
||||||
|
Target: "https://test.env.com$request_uri",
|
||||||
|
Host: "test.env.com",
|
||||||
|
}},
|
||||||
|
{map[string]string{backendURL: "https://test.env.com:8080$request_uri"}, &Config{
|
||||||
|
Source: ngxURI,
|
||||||
|
RequestBody: "on",
|
||||||
|
Target: "https://test.env.com:8080$request_uri",
|
||||||
|
Host: "test.env.com",
|
||||||
|
}},
|
||||||
|
{map[string]string{backendURL: "https://test.env.com:8080/$request_uri"}, &Config{
|
||||||
|
Source: ngxURI,
|
||||||
|
RequestBody: "on",
|
||||||
|
Target: "https://test.env.com:8080/$request_uri",
|
||||||
|
Host: "test.env.com",
|
||||||
|
}},
|
||||||
{map[string]string{requestBody: "off"}, &Config{
|
{map[string]string{requestBody: "off"}, &Config{
|
||||||
Source: "",
|
Source: "",
|
||||||
RequestBody: "off",
|
RequestBody: "off",
|
||||||
|
|
Loading…
Reference in a new issue