Skip to content

Commit

Permalink
bugfix: fix upstream get unwanted /. (envoyproxy#3990)
Browse files Browse the repository at this point in the history
* bugfix: fix upstream get unwanted /.

Signed-off-by: qicz <qiczzhu@gmail.com>

* ut for bugfix

Signed-off-by: qicz <qiczzhu@gmail.com>

---------

Signed-off-by: qicz <qiczzhu@gmail.com>
Co-authored-by: Xunzhuo <bitliu@tencent.com>
  • Loading branch information
qicz and Xunzhuo authored Aug 5, 2024
1 parent c2c705b commit b77f6a4
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/xds/translator/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ func buildXdsURLRewriteAction(destName string, urlRewrite *ir.URLRewrite, pathMa
if useRegexRewriteForPrefixMatchReplace(pathMatch, *urlRewrite.Path.PrefixMatchReplace) {
routeAction.RegexRewrite = prefix2RegexRewrite(*pathMatch.Prefix)
} else {
routeAction.PrefixRewrite = *urlRewrite.Path.PrefixMatchReplace
// remove trailing / to fix #3989
// when the pathMath.Prefix has suffix / but EG has removed it,
// and the urlRewrite.Path.PrefixMatchReplace suffix with / the upstream will get unwanted /
routeAction.PrefixRewrite = strings.TrimSuffix(*urlRewrite.Path.PrefixMatchReplace, "/")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "http-route"
http:
- name: "first-listener"
address: "0.0.0.0"
port: 10080
hostnames:
- "*"
path:
mergeSlashes: true
escapedSlashesAction: UnescapeAndRedirect
routes:
- name: "rewrite-route"
pathMatch:
prefix: "/origin/"
hostname: gateway.envoyproxy.io
headerMatches:
- name: ":authority"
exact: gateway.envoyproxy.io
destination:
name: "rewrite-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50000
urlRewrite:
path:
prefixMatchReplace: /rewrite/
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- circuitBreakers:
thresholds:
- maxRetries: 1024
commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
serviceName: rewrite-route-dest
lbPolicy: LEAST_REQUEST
name: rewrite-route-dest
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- clusterName: rewrite-route-dest
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
loadBalancingWeight: 1
loadBalancingWeight: 1
locality:
region: rewrite-route-dest/backend/0
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
- 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
commonHttpProtocolOptions:
headersWithUnderscoresAction: REJECT_REQUEST
http2ProtocolOptions:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
maxConcurrentStreams: 100
httpFilters:
- name: envoy.filters.http.router
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
suppressEnvoyHeaders: true
mergeSlashes: true
normalizePath: true
pathWithEscapedSlashesAction: UNESCAPE_AND_REDIRECT
rds:
configSource:
ads: {}
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
useRemoteAddress: true
name: first-listener
drainType: MODIFY_ONLY
name: first-listener
perConnectionBufferLimitBytes: 32768
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- ignorePortInHostMatching: true
name: first-listener
virtualHosts:
- domains:
- gateway.envoyproxy.io
name: first-listener/gateway_envoyproxy_io
routes:
- match:
headers:
- name: :authority
stringMatch:
exact: gateway.envoyproxy.io
pathSeparatedPrefix: /origin
name: rewrite-route
route:
cluster: rewrite-route-dest
prefixRewrite: /rewrite
upgradeConfigs:
- upgradeType: websocket

0 comments on commit b77f6a4

Please sign in to comment.