SpringCloudAlibaba+Nacos integration Gateway
Spring cloud gateway combined with Sentienl to implement gateway current limiting mechanism
Instructions for use of various types of predicates built in Spring Cloud Gateway
Routing filters allow you to modify incoming HTTP requests or outgoing HTTP responses in some way. The scope of the route filter is a specific route. Spring Cloud Gateway includes many built-in GatewayFilter factories. The common filters are summarized below.
1,AddRequestHeader
AddRequestHeader consists of two parameters: the first is the header name and the second is the header value.
yaml configuration:
spring: cloud: gateway: routes: - id: user-service uri: lb://user-service predicates: - Path=/user/** filters: - AddRequestHeader=X-Request-red, blue
Configuration: in the request header, set name as X-Request-red and value as blue; Then the filter passes the header information to the downstream header.
Test:
2,RemoveRequestHeader
RemoveRequestHeader is a parameter of header name, which is the name of the header to be deleted.
yaml configuration:
spring: cloud: gateway: routes: - id: user-service uri: lb://user-service predicates: - Path=/user/** filters: - RemoveRequestHeader=X-Request-Foo
Configuration: in the request, set the header name to be deleted; The filter then deletes the header information before passing it to the downstream service.
Test:
3,SetRequestHeader
SetRequestHeader consists of two parameters: the first is the header name and the second is the header value.
yaml configuration:
spring: cloud: gateway: routes: - id: user-service uri: lb://user-service predicates: - Path=/user/** filters: - SetRequestHeader=X-Request-Red, Blue
The configuration is: SetRequestHeader will replace the value of the original header name. In the request header, set the name to X-Request-Red and the value to blue; Then, the filter replaces the original value of the header with blue and passes it to the downstream header.
Test:
4,AddRequestParameter
AddRequestParameter consists of two parameters: the first is the name of the parameter and the second is the value of the parameter.
yaml configuration:
spring: cloud: gateway: routes: - id: user-service uri: lb://user-service predicates: - Path=/user/** filters: - AddRequestParameter=color, blue
Configuration: add a group of parameters with name as color and value as blue in the gateway filter when requesting; The filter then passes the set of parameters to the downstream service.
Test:
5,RemoveRequestParameter
RemoveRequestParameter is a parameter that specifies the name of the parameter. It is the name of the query parameter to be deleted.
yaml configuration:
spring: cloud: gateway: routes: - id: user-service uri: lb://user-service predicates: - Path=/user/** filters: - RemoveRequestParameter=color
Configuration: in the request, set the parameter name to be deleted; The filter then deletes the parameter information before passing it to the downstream service.
Test:
6,AddResponseHeader
AddResponseHeader consists of two parameters: the first is the header name and the second is the header value.
yaml configuration:
spring: cloud: gateway: routes: - id: user-service uri: lb://user-service predicates: - Path=/user/** filters: - AddResponseHeader=X-Response-Red, Blue
Configuration: set name to X-Response-Red and value to Blue; Then the filter passes the header information to the response header of the downstream service.
Test:
7,RemoveResponseHeader
RemoveResponseHeader is a parameter of header name, which is the name of the header to be deleted in response.
yaml configuration:
spring: cloud: gateway: routes: - id: user-service uri: lb://user-service predicates: - Path=/user/** filters: - RemoveResponseHeader=X-Response-Foo
Configuration: in the request, set the header name to be deleted; The filter then removes the header information from the response before returning it to the gateway client.
Test:
8,SetResponseHeader
SetResponseHeader consists of two parameters: the first is the header name and the second is the new header value.
yaml configuration:
spring: cloud: gateway: routes: - id: user-service uri: lb://user-service predicates: - Path=/user/** filters: - SetRequestHeader=X-Request-Red, Blue
The configuration is: SetResponseHeader will replace the value of the original header name. In the request header, set the name to X-Request-Red and the value to Blue; The filter then replaces the header information with Blue before returning it to the gateway client.
Test: