当前位置:网站首页>[micro service SCG] 33 usages of filters
[micro service SCG] 33 usages of filters
2022-07-05 02:35:00 【Bulst】
List of articles
- Add request header / Request parameters / Response head
- New news header Request header
- Set request header 、 Filter configuration , Modify or remove the request header
- PreserveHostHeader
- rewrite response Encrypted password
- response duplicate removal
- Path prefixed
- To configure 30 A few Jump to the specified address
- Modify the status code
- Forwarding address
- Get rid of \ Add some levels in the request path
- Retry filter
- The filter sets the request size
- spring-session
- Default filter
Add request header / Request parameters / Response head
spring:
cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: ossa-service-producer
uri: lb://ossa-service-producer
predicates:
- Path=/gw/producer/**
- After=2022-03-03T15:50:30.337+08:00[Asia/Shanghai]
- Before=2024-03-03T15:50:30.337+08:00[Asia/Shanghai]
filters:
- StripPrefix=1
# Add request header 、 Request parameters
- AddRequestHeader=origin-header,producer-header
- AddRequestParameter= origin-param,producer-param
- AddResponseHeader=rep-header,rep-header
New news header Request header
spring:
cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: ossa-service-producer
uri: lb://ossa-service-producer
predicates:
- Path=/gw/producer/{
id}
- After=2022-03-03T15:50:30.337+08:00[Asia/Shanghai]
- Before=2024-03-03T15:50:30.337+08:00[Asia/Shanghai]
filters:
- StripPrefix=1
# Add request header 、 Request parameters
- AddRequestHeader=origin-header,producer-header-{
id}
Set request header 、 Filter configuration , Modify or remove the request header
filters:
- StripPrefix=1
# Add request header 、 Request parameters
- AddRequestHeader=origin-header,producer-header-{
id}
- AddRequestParameter=origin-param,producer-param
- AddResponseHeader=rep-header,rep-header
# Set request header , If not, add , It was modified
- SetRequestHeader=X-Request-id,value
# Remove request header 、 Request parameters
- RemoveRequestHeader=X-Request-id
- RemoveRequestParameter=X-Request
- RemoveRequestParameter=X-Request-author
- AddResponseHeader=req-param,req-param
# First from header take from-Header, If so, assign to to-Header, If not from-Header No effect
- MapRequestHeader=from-Header,to-Header
PreserveHostHeader
Default on , stay gateway Forward the original request before forwarding the request host Put it on your head , Forward to the destination service .
spring:
cloud:
gateway:
routes:
- id: preserve_host_route
uri: https://example.org
filters:
- PreserveHostHeader
rewrite response Encrypted password
# for example : /42?user=ford&passwd=omg!what&flag=true After the following configuration, replace with /42?user=ford&passwd=***&flag=true
spring:
cloud:
gateway:
routes:
- id: rewriteresponseheader_route
uri: https://example.org
filters:
- RewriteResponseHeader=X-Response-Red, , password=[^&]+, password=***
response duplicate removal
RETAIN_FIRST Keep the first (default)
RETAIN_LAST Keep the last one
RETAIN_FIRST RETAIN_UNIQUE Keep unique
spring:
cloud:
gateway:
routes:
- id: dedupe_response_header_route
uri: https://example.org
filters:
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
Path prefixed
request / It's actually /mypath
spring:
cloud:
gateway:
routes:
- id: prefixpath_route
uri: https://example.org
filters:
- PrefixPath=/mypath
To configure 30 A few Jump to the specified address
#300 Multiple Multiple choice , The requested resource may include multiple locations , Accordingly, a list of resource characteristics and addresses can be returned for user terminal selection
#301 Moved Permanently A permanent move , The new location of the requested resource has been permanently moved , The returned information will contain URI, The browser will automatically direct to the new address , Future requests should use new URI Instead of
#302 Found Temporary movement , And 301 similar , Resources are temporarily moved , The client should continue to use the original URI
#303 See Other View other addresses , And 301 similar . Use GET and POST Request to view
#304 not changed , The requested resource has not been modified , When the server returns to this state , No resources will be returned
#305 Use proxy Using agents , The requested resource must be through a proxy
#306 Unused Abandoned HTTP Status code
#307 Temporary Redirect Temporary redirection , And 302 similar , Use GET request redirections
- RedirectTo=302,http://www.baidu.com
- RedirectTo=301,http://www.taobao.com
Modify the status code
Modify the status code , Sure org.springframework.http.HttpStatus enumeration , You can also write the status code directly
In either case , Responsive HTTP The status is set to 401.
spring:
cloud:
gateway:
routes:
- id: setstatusstring_route
uri: https://example.org
filters:
- SetStatus=UNAUTHORIZED
- id: setstatusint_route
uri: https://example.org
filters:
- SetStatus=401
Forwarding address
visit /api/getheader Actual visit :/getheader, The destination address of forwarding must be / Otherwise it will go wrong
- RewritePath=/consumingServiceEndpoint, /backingServiceEndpoint
spring:
cloud:
gateway:
routes:
- id: rewritepath_route
uri: https://example.org
predicates:
- Path=/red/**
filters:
- RewritePath=/red/?(?<segment>.*), /$\{
segment}
Get rid of \ Add some levels in the request path
request /name/first/123 Actual request /123
spring:
cloud:
gateway:
routes:
- id: nameRoot
uri: https://nameservice
predicates:
- Path=/name/first/**
filters:
# Remove some paths from the front to the back
- StripPrefix=2
request /name/first/123 Actual request /prefix/name/first/123
spring:
cloud:
gateway:
routes:
- id: nameRoot
uri: https://nameservice
predicates:
- Path=/name/first/**
filters:
# Add prefix path
- PrefixPath=/prefix
Retry filter
spring:
cloud:
gateway:
routes:
- id: retry_test
uri: http://localhost:8080/flakey
predicates:
- Host=*.retry.com
filters:
- name: Retry
args:
retries: 3
statuses: BAD_GATEWAY
methods: GET,POST
backoff:
firstBackoff: 10ms
maxBackoff: 50ms
factor: 2
basedOnPreviousValue: false
The filter sets the request size
filters:
- name: RequestSize # Filter name
args: # Control the size of the request , More than that, return to 413. Request maximum default 5000000 about 5M
maxSize:1000 #1KB
spring-session
Only when integrated Spring Session Will be session Put it in Redis, To share Session function , If the project inherits Spring Session Medium Spring Security frame , If you want the security authentication information, you can forward it to the remote application , Then this configuration is necessary .
filters:
- SaveSession
Default filter
spring:
cloud:
gateway:
default-filters:
- AddResponseHeader=X-Response-Default-Red, Default-Blue
- PrefixPath=/httpbin
边栏推荐
- Hmi-31- [motion mode] solve the problem of picture display of music module
- Advanced learning of MySQL -- Application -- Introduction
- 低度酒赛道进入洗牌期,新品牌如何破局三大难题?
- Can you really learn 3DMAX modeling by self-study?
- The phenomenology of crypto world: Pioneer entropy
- 2022/02/13
- ASP. Net core 6 framework unveiling example demonstration [01]: initial programming experience
- How to make a cool ink screen electronic clock?
- [技术发展-26]:新型信息与通信网络的数据安全
- 【LeetCode】98. Verify the binary search tree (2 brushes of wrong questions)
猜你喜欢

【LeetCode】106. Construct binary tree from middle order and post order traversal sequence (wrong question 2)

Yolov5 model training and detection

Can you really learn 3DMAX modeling by self-study?

ELK日志分析系统

丸子百度小程序详细配置教程,审核通过。
![Hmi-32- [motion mode] add light panel and basic information column](/img/9c/0b25c0a41758652848aed2a269880f.jpg)
Hmi-32- [motion mode] add light panel and basic information column

The MySQL team development specifications used by various factories are too detailed. It is recommended to collect them!

Bert fine tuning skills experiment

Video display and hiding of imitation tudou.com
![[technology development-26]: data security of new information and communication networks](/img/13/10c8bd340017c6516edef41cd3bf6f.png)
[technology development-26]: data security of new information and communication networks
随机推荐
Timescaledb 2.5.2 release, time series database based on PostgreSQL
The steering wheel can be turned for one and a half turns. Is there any difference between it and two turns
Summary and practice of knowledge map construction technology
openresty ngx_lua变量操作
Binary tree traversal - middle order traversal (golang)
Tucson will lose more than $400million in the next year
[understanding of opportunity -38]: Guiguzi - Chapter 5 flying clamp - warning one: there is a kind of killing called "killing"
Practice of tdengine in TCL air conditioning energy management platform
openresty ngx_ Lua variable operation
GFS distributed file system
Limited query of common SQL operations
tuple and point
Elk log analysis system
spoon插入更新oracle数据库,插了一部分提示报错Assertion botch: negative time
A tab Sina navigation bar
[Digital IC hand tearing code] Verilog edge detection circuit (rising edge, falling edge, double edge) | topic | principle | design | simulation
Which common ports should the server open
Marubeni Baidu applet detailed configuration tutorial, approved.
Hmi-31- [motion mode] solve the problem of picture display of music module
Visual studio 2019 set transparent background (fool teaching)