Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix PathSeparatedPrefix & optimize the prefix ends with / logic. #1125

Merged
merged 1 commit into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 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,10 @@ func buildXdsRouteMatch(pathMatch *ir.StringMatch, headerMatches []*ir.StringMat
Path: *pathMatch.Exact,
}
} else if pathMatch.Prefix != nil {
if *pathMatch.Prefix == "/" {
// when the prefix ends with "/", use RouteMatch_Prefix
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