1. Overview
1.1 Plugin Name
- Request Plugin
1.2 Appropriate Scenario
- The request plugin is able to make customized changes to the request parameters of
uri.
1.3 Plugin functionality
- The
Apache ShenYugateway allows users to use therequestplugin to add, modify, and remove request headers to request parameters, request headers, andCookiewhen proxying a target service.
1.4 Plugin code
-
Core Module
shenyu-plugin-request -
Core Class
org.apache.shenyu.plugin.request.RequestPlugin
1.5 Added Since Which shenyu version
- Since ShenYu 2.4.0
2. How to use plugin
2.1 Plugin-use procedure chart
2.2 Import pom
- Import maven config in shenyu-bootstrap project's
pom.xmlfile, which is already added by default.
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-plugin-request</artifactId>
<version>${project.version}</version>
</dependency>
2.3 Enable plugin
-
In
shenyu-admin--> BasicConfig --> Plugin -->requestset Status enabled.If there is an option to configure a
ruleHandlePageTypeon the page here, you can configure any string, e.g.custom, which has no effect on the request, and will be removed in later versions.
2.4 Config plugin
-
selectors and rules, only requests that match are forwarded and redirected, see the Selector And Rule Config
-
shenyu-adminPlugin -->HttpProcess-->Request. Add the selector first, then add the rule: -
Add the selector:
-
Add the rule
2.5 Examples
2.5.1 Adding request parameters
- When we configure a custom path in
Rules, it should be a reachable service path. - When a request is matched, based on the customized path, the
Apache ShenYugateway performs a service hop.
- Refer to Local Deployment启动 admin 和网关
- Refer to 2.2 importing pom and restarting the gateway.
- Refer to 2.3 enabling Plugin
- Start the project shenyu-examples-http
- Refer to 2.4 and Selector And Rule Config, configuring plugin rules.
- Call interface:http-test-api.http
-
Calling the interface declared by the selector and rule will see the request parameters configured in the request plugin.
3. How to disable plugin
- In
shenyu-admin--> BasicConfig --> Plugin -->requestset Status disable. -