You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by xi...@apache.org on 2022/12/05 07:11:18 UTC

[shenyu] branch master updated: [Task] support user specify http request domain (#4233)

This is an automated email from the ASF dual-hosted git repository.

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 3fb38b32a [Task] support user specify http request domain (#4233)
3fb38b32a is described below

commit 3fb38b32a1c5c042aa04b4bec9aed4b1e8082f5c
Author: mahaitao <15...@163.com>
AuthorDate: Mon Dec 5 15:11:10 2022 +0800

    [Task] support user specify http request domain (#4233)
    
    * feat:support user to self define http request domain
    
    * feat:fix
    
    * feat:fix
    
    * feat:fix
    
    Co-authored-by: mahaitao617 <ma...@mahaitao617deMacBook-Pro.local>
---
 .../src/main/java/org/apache/shenyu/common/constant/Constants.java   | 5 +++++
 .../src/main/java/org/apache/shenyu/plugin/divide/DividePlugin.java  | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
index 5ec980e11..c060165c3 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
@@ -637,6 +637,11 @@ public interface Constants {
      */
     String CACHED = "cached";
 
+    /**
+     * user can use the specify-domian to replace of upstream url of the divide plugin.
+     */
+    String SPECIFY_DOMAIN = "specify-domain";
+
     /**
      * The maximum free memory reserved by the blocking queue for the JVM.
      */
diff --git a/shenyu-plugin/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/DividePlugin.java b/shenyu-plugin/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/DividePlugin.java
index 7ead17ed9..1cf21eada 100644
--- a/shenyu-plugin/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/DividePlugin.java
+++ b/shenyu-plugin/shenyu-plugin-divide/src/main/java/org/apache/shenyu/plugin/divide/DividePlugin.java
@@ -95,6 +95,10 @@ public class DividePlugin extends AbstractShenyuPlugin {
             return WebFluxResultUtils.result(exchange, error);
         }
         // set the http url
+        if (CollectionUtils.isNotEmpty(exchange.getRequest().getHeaders().get(Constants.SPECIFY_DOMAIN))) {
+            upstream.setUrl(exchange.getRequest().getHeaders().get(Constants.SPECIFY_DOMAIN).get(0));
+        }
+        // set domain
         String domain = upstream.buildDomain();
         exchange.getAttributes().put(Constants.HTTP_DOMAIN, domain);
         // set the http timeout