Skip to content

Commit

Permalink
fix PathSeparatedPrefix & optimize prefix endwith / logic
Browse files Browse the repository at this point in the history
Signed-off-by: qicz <[email protected]>
  • Loading branch information
qicz committed Mar 10, 2023
1 parent 38470e0 commit 9d0d6f3
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/xds/translator/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package translator

import (
"fmt"
"strings"

corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
listenerv3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
Expand Down Expand Up @@ -96,9 +97,11 @@ func buildXdsRouteMatch(pathMatch *ir.StringMatch, headerMatches []*ir.StringMat
Path: *pathMatch.Exact,
}
} else if pathMatch.Prefix != nil {
if *pathMatch.Prefix == "/" {
// when prefix end with "/" use RouteMatch_Prefix
// https://github.com/envoyproxy/gateway/issues/1044
if strings.HasSuffix(*pathMatch.Prefix, "/") {
outMatch.PathSpecifier = &routev3.RouteMatch_Prefix{
Prefix: "/",
Prefix: *pathMatch.Prefix,
}
} else {
outMatch.PathSpecifier = &routev3.RouteMatch_PathSeparatedPrefix{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "http-route"
http:
- name: "first-listener"
address: "0.0.0.0"
port: 10080
hostnames:
- "*"
routes:
- name: "rewrite-route"
pathMatch:
prefix: "/origin/"
headerMatches:
- name: ":authority"
exact: gateway.envoyproxy.io
destinations:
- host: "1.2.3.4"
port: 50000
urlRewrite:
path:
prefixMatchReplace: /
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
loadAssignment:
clusterName: rewrite-route
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
loadBalancingWeight: 1
locality: {}
name: rewrite-route
outlierDetection: {}
type: STATIC
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- accessLog:
- filter:
responseFlagFilter:
flags:
- NR
name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
address:
socketAddress:
address: 0.0.0.0
portValue: 10080
defaultFilterChain:
filters:
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.router
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
rds:
configSource:
ads: {}
resourceApiVersion: V3
routeConfigName: first-listener
statPrefix: http
upgradeConfigs:
- upgradeType: websocket
useRemoteAddress: true
name: first-listener
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: first-listener
virtualHosts:
- domains:
- '*'
name: first-listener
routes:
- match:
headers:
- name: :authority
stringMatch:
exact: gateway.envoyproxy.io
prefix: /origin/
route:
cluster: rewrite-route
prefixRewrite: /
3 changes: 3 additions & 0 deletions internal/xds/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func TestTranslateXds(t *testing.T) {
{
name: "http-route-rewrite-url-prefix",
},
{
name: "http-route-rewrite-root-path-url-prefix",
},
{
name: "http-route-rewrite-url-fullpath",
},
Expand Down

0 comments on commit 9d0d6f3

Please sign in to comment.