Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 873c0f41
authored
Oct 16, 2023
by
刘鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: URLEncode 编码后的url参数解析
1 parent
fc30f692
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
9 deletions
project-gateway/src/main/java/com/dituhui/pea/gateway/config/GatewayConfig.java
project-gateway/src/main/java/com/dituhui/pea/gateway/config/GlobalRequestUrlDecodeFilter.java
project-gateway/src/main/java/com/dituhui/pea/gateway/config/GatewayConfig.java
View file @
873c0f4
...
...
@@ -16,21 +16,12 @@
package
com
.
dituhui
.
pea
.
gateway
.
config
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
javax.annotation.PostConstruct
;
import
com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule
;
import
com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager
;
import
com.alibaba.csp.sentinel.adapter.gateway.sc.SentinelGatewayFilter
;
import
com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler
;
import
com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager
;
import
com.alibaba.csp.sentinel.adapter.gateway.sc.exception.SentinelGatewayBlockExceptionHandler
;
import
reactor.core.publisher.Mono
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -47,6 +38,13 @@ import org.springframework.web.reactive.function.BodyInserters;
import
org.springframework.web.reactive.function.server.ServerResponse
;
import
org.springframework.web.reactive.result.view.ViewResolver
;
import
org.springframework.web.server.ServerWebExchange
;
import
reactor.core.publisher.Mono
;
import
javax.annotation.PostConstruct
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author TrevorLink
...
...
@@ -113,4 +111,9 @@ public class GatewayConfig {
return
new
CorsWebFilter
(
source
);
}
@Bean
public
GlobalRequestUrlDecodeFilter
globalRequestUrlDecodeFilter
()
{
return
new
GlobalRequestUrlDecodeFilter
();
}
}
project-gateway/src/main/java/com/dituhui/pea/gateway/config/GlobalRequestUrlDecodeFilter.java
0 → 100644
View file @
873c0f4
package
com
.
dituhui
.
pea
.
gateway
.
config
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.core.Ordered
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.util.UriComponents
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
reactor.core.publisher.Mono
;
import
java.net.URI
;
import
java.net.URLDecoder
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
/**
* URI 参数过滤
*
* @author lsy_xin 2022/3/3 16:29:29
*/
@Slf4j
@AllArgsConstructor
public
class
GlobalRequestUrlDecodeFilter
implements
GlobalFilter
,
Ordered
{
@Override
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
ServerHttpRequest
request
=
exchange
.
getRequest
();
URI
uri
=
request
.
getURI
();
String
path
=
uri
.
getPath
();
String
decodePath
=
URLDecoder
.
decode
(
path
,
StandardCharsets
.
UTF_8
);
ServerHttpRequest
newRequest
=
exchange
.
getRequest
().
mutate
().
path
(
decodePath
).
build
();
return
chain
.
filter
(
exchange
.
mutate
().
request
(
newRequest
).
build
());
}
@Override
public
int
getOrder
()
{
return
Integer
.
MIN_VALUE
+
1
;
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment