mirror of
https://github.com/containous/traefik.git
synced 2025-10-22 19:33:20 +03:00
Add edge case for root path with rewrite-target
This commit is contained in:
committed by
Traefiker Bot
parent
a8393faf0a
commit
3f1925e20e
@@ -161,6 +161,23 @@ spec:
|
|||||||
servicePort: 80
|
servicePort: 80
|
||||||
path: /api
|
path: /api
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
ingress.kubernetes.io/rewrite-target: /app
|
||||||
|
namespace: testing
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: rewritetargetrootpath
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- backend:
|
||||||
|
serviceName: service1
|
||||||
|
servicePort: 80
|
||||||
|
path: /
|
||||||
|
|
||||||
---
|
---
|
||||||
apiVersion: extensions/v1beta1
|
apiVersion: extensions/v1beta1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
|
@@ -674,6 +674,12 @@ func getRuleForPath(pa extensionsv1beta1.HTTPIngressPath, i *extensionsv1beta1.I
|
|||||||
return "", fmt.Errorf("rewrite-target must not be used together with annotation %q", annotationKubernetesRuleType)
|
return "", fmt.Errorf("rewrite-target must not be used together with annotation %q", annotationKubernetesRuleType)
|
||||||
}
|
}
|
||||||
rewriteTargetRule := fmt.Sprintf("ReplacePathRegex: ^%s(.*) %s$1", pa.Path, strings.TrimRight(rewriteTarget, "/"))
|
rewriteTargetRule := fmt.Sprintf("ReplacePathRegex: ^%s(.*) %s$1", pa.Path, strings.TrimRight(rewriteTarget, "/"))
|
||||||
|
if pa.Path == "/" {
|
||||||
|
// If path = /, then just append the cap group, as if we don't cap the path as part of the regex,
|
||||||
|
// then when we strip the right / from the rewrite target, it ends up being missed, as removed but never returned
|
||||||
|
// this only happens when path = / because it is the only case where TrimRight will catch a leading /.
|
||||||
|
rewriteTargetRule = fmt.Sprintf("ReplacePathRegex: ^(.*) %s$1", strings.TrimRight(rewriteTarget, "/"))
|
||||||
|
}
|
||||||
rules = append(rules, rewriteTargetRule)
|
rules = append(rules, rewriteTargetRule)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -415,6 +415,12 @@ func TestProvider_loadIngresses(t *testing.T) {
|
|||||||
server("http://example.com", weight(1))),
|
server("http://example.com", weight(1))),
|
||||||
lbMethod("wrr"),
|
lbMethod("wrr"),
|
||||||
),
|
),
|
||||||
|
backend("rewritetargetrootpath/",
|
||||||
|
servers(
|
||||||
|
server("http://example.com", weight(1)),
|
||||||
|
server("http://example.com", weight(1))),
|
||||||
|
lbMethod("wrr"),
|
||||||
|
),
|
||||||
backend("error-pages/errorpages",
|
backend("error-pages/errorpages",
|
||||||
servers(
|
servers(
|
||||||
server("http://example.com", weight(1)),
|
server("http://example.com", weight(1)),
|
||||||
@@ -523,6 +529,12 @@ func TestProvider_loadIngresses(t *testing.T) {
|
|||||||
route("/whitelist-source-range", "PathPrefix:/whitelist-source-range"),
|
route("/whitelist-source-range", "PathPrefix:/whitelist-source-range"),
|
||||||
route("test", "Host:test")),
|
route("test", "Host:test")),
|
||||||
),
|
),
|
||||||
|
frontend("rewritetargetrootpath/",
|
||||||
|
passHostHeader(),
|
||||||
|
routes(
|
||||||
|
route("/", "PathPrefix:/;ReplacePathRegex: ^(.*) /app$1"),
|
||||||
|
route("rewritetargetrootpath", "Host:rewritetargetrootpath")),
|
||||||
|
),
|
||||||
frontend("rewrite/api",
|
frontend("rewrite/api",
|
||||||
passHostHeader(),
|
passHostHeader(),
|
||||||
routes(
|
routes(
|
||||||
@@ -596,7 +608,7 @@ func TestProvider_loadIngresses(t *testing.T) {
|
|||||||
passHostHeader(),
|
passHostHeader(),
|
||||||
redirectRegex("root2/$", "root2/root2"),
|
redirectRegex("root2/$", "root2/root2"),
|
||||||
routes(
|
routes(
|
||||||
route("/", "PathPrefix:/;ReplacePathRegex: ^/(.*) /abc$1"),
|
route("/", "PathPrefix:/;ReplacePathRegex: ^(.*) /abc$1"),
|
||||||
route("root2", "Host:root2"),
|
route("root2", "Host:root2"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user