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/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 992eaf26c [type: refactor] Optimize shenyu proxy and webclient remove 
host (#3262)
992eaf26c is described below

commit 992eaf26c75ed44be38225ee16b564a00363db18
Author: xiaoyu <[email protected]>
AuthorDate: Mon Apr 18 15:01:04 2022 +0800

    [type: refactor] Optimize shenyu proxy and webclient remove host (#3262)
    
    * [type: refactor] Optimize shenyu proxy and webclient remove host
    
    * fix ci
    
    * fix ci
---
 .../shenyu/plugin/httpclient/WebClientPlugin.java  |  1 -
 shenyu-proxy/pom.xml                               | 14 ++---
 .../{proxy-remote => shenyu-proxy-remote}/pom.xml  | 12 ++---
 .../apache/shenyu/proxy/remote/AbstractServer.java |  0
 .../org/apache/shenyu/proxy/remote/Channel.java    |  0
 .../apache/shenyu/proxy/remote/ChannelFuture.java  |  0
 .../apache/shenyu/proxy/remote/ChannelHandler.java |  0
 .../org/apache/shenyu/proxy/remote/Server.java     |  0
 .../apache/shenyu/proxy/remote/ServerConfig.java   |  0
 .../shenyu/proxy/remote/netty/NettyChannel.java    |  0
 .../proxy/remote/netty/NettyChannelFuture.java     |  0
 .../shenyu/proxy/remote/netty/NettyServer.java     | 61 ++++++++++------------
 .../proxy/remote/netty/NettyServerHandler.java     |  1 -
 .../shenyu/proxy/remote/NettyServerTest.java       |  0
 14 files changed, 36 insertions(+), 53 deletions(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/WebClientPlugin.java
 
b/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/WebClientPlugin.java
index 6b797c919..a1aa2d6d5 100644
--- 
a/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/WebClientPlugin.java
+++ 
b/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/WebClientPlugin.java
@@ -63,7 +63,6 @@ public class WebClientPlugin extends 
AbstractHttpClientPlugin<ClientResponse> {
             acceptEncoding.remove(Constants.HTTP_ACCEPT_ENCODING_GZIP);
             headers.set(HttpHeaders.ACCEPT_ENCODING, String.join(",", 
acceptEncoding));
         }
-        headers.remove(HttpHeaders.HOST);
         return headers;
     }
 
diff --git a/shenyu-proxy/pom.xml b/shenyu-proxy/pom.xml
index accee5c8f..6e5ab77c5 100644
--- a/shenyu-proxy/pom.xml
+++ b/shenyu-proxy/pom.xml
@@ -20,17 +20,18 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
     <parent>
-        <artifactId>shenyu</artifactId>
         <groupId>org.apache.shenyu</groupId>
-        <version>2.4.3-SNAPSHOT</version>
+        <artifactId>shenyu</artifactId>
+        <version>2.5.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-
     <artifactId>shenyu-proxy</artifactId>
     <packaging>pom</packaging>
+    
     <modules>
-        <module>proxy-remote</module>
+        <module>shenyu-proxy-remote</module>
     </modules>
+    
     <dependencies>
         <dependency>
             <groupId>org.apache.shenyu</groupId>
@@ -39,9 +40,4 @@
         </dependency>
     </dependencies>
 
-    <properties>
-        <maven.compiler.source>8</maven.compiler.source>
-        <maven.compiler.target>8</maven.compiler.target>
-    </properties>
-
 </project>
\ No newline at end of file
diff --git a/shenyu-proxy/proxy-remote/pom.xml 
b/shenyu-proxy/shenyu-proxy-remote/pom.xml
similarity index 85%
rename from shenyu-proxy/proxy-remote/pom.xml
rename to shenyu-proxy/shenyu-proxy-remote/pom.xml
index b92a8118b..b12b42451 100644
--- a/shenyu-proxy/proxy-remote/pom.xml
+++ b/shenyu-proxy/shenyu-proxy-remote/pom.xml
@@ -20,22 +20,18 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
     <parent>
-        <artifactId>shenyu-proxy</artifactId>
         <groupId>org.apache.shenyu</groupId>
-        <version>2.4.3-SNAPSHOT</version>
+        <artifactId>shenyu-proxy</artifactId>
+        <version>2.5.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>proxy-remote</artifactId>
+    <artifactId>shenyu-proxy-remote</artifactId>
+    
     <dependencies>
         <dependency>
             <groupId>io.netty</groupId>
             <artifactId>netty-all</artifactId>
         </dependency>
     </dependencies>
-    <properties>
-        <maven.compiler.source>8</maven.compiler.source>
-        <maven.compiler.target>8</maven.compiler.target>
-    </properties>
 
 </project>
\ No newline at end of file
diff --git 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/AbstractServer.java
 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/AbstractServer.java
similarity index 100%
rename from 
shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/AbstractServer.java
rename to 
shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/AbstractServer.java
diff --git 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/Channel.java
 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/Channel.java
similarity index 100%
rename from 
shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/Channel.java
rename to 
shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/Channel.java
diff --git 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ChannelFuture.java
 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ChannelFuture.java
similarity index 100%
rename from 
shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ChannelFuture.java
rename to 
shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ChannelFuture.java
diff --git 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ChannelHandler.java
 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ChannelHandler.java
similarity index 100%
rename from 
shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ChannelHandler.java
rename to 
shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ChannelHandler.java
diff --git 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/Server.java
 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/Server.java
similarity index 100%
rename from 
shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/Server.java
rename to 
shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/Server.java
diff --git 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ServerConfig.java
 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ServerConfig.java
similarity index 100%
rename from 
shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ServerConfig.java
rename to 
shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/ServerConfig.java
diff --git 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyChannel.java
 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyChannel.java
similarity index 100%
rename from 
shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyChannel.java
rename to 
shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyChannel.java
diff --git 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyChannelFuture.java
 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyChannelFuture.java
similarity index 100%
rename from 
shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyChannelFuture.java
rename to 
shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyChannelFuture.java
diff --git 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServer.java
 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServer.java
similarity index 78%
rename from 
shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServer.java
rename to 
shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServer.java
index ef48e3af6..e93ad58a0 100644
--- 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServer.java
+++ 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServer.java
@@ -23,6 +23,7 @@ import io.netty.channel.Channel;
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.ChannelOption;
 import io.netty.channel.EventLoopGroup;
+import io.netty.channel.epoll.Epoll;
 import io.netty.channel.epoll.EpollEventLoopGroup;
 import io.netty.channel.epoll.EpollServerSocketChannel;
 import io.netty.channel.nio.NioEventLoopGroup;
@@ -38,10 +39,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.net.InetSocketAddress;
+import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 
 /**
- * NettyServer .
+ * Shenyu NettyServer.
  * netty network management.
  */
 public class NettyServer extends AbstractServer {
@@ -56,16 +58,15 @@ public class NettyServer extends AbstractServer {
     /**
      * service processing.
      */
-    private EventLoopGroup boosGroup;
+    private EventLoopGroup bossGroup;
     
     /**
      * task processing thread.
      */
-    private EventLoopGroup workGroup;
+    private EventLoopGroup workerGroup;
     
     private final int threads = Runtime.getRuntime().availableProcessors() << 
1;
     
-    
     /**
      * Instantiates a new Abstract server.
      */
@@ -81,18 +82,25 @@ public class NettyServer extends AbstractServer {
      */
     @Override
     protected void start0(final int port) {
-        //Judge Linux system
-        if (isLinux()) {
-            boosGroup = new EpollEventLoopGroup(1, 
ShenyuThreadFactory.create("shenyu_proxy_server_boss_epoll", false));
-            workGroup = new EpollEventLoopGroup(threads, 
ShenyuThreadFactory.create("shenyu_proxy_server_work_epoll", false));
-            server.channel(EpollServerSocketChannel.class);
-        } else {
-            boosGroup = new NioEventLoopGroup(1, 
ShenyuThreadFactory.create("shenyu_proxy_server_boss_epoll", false));
-            workGroup = new NioEventLoopGroup(threads, 
ShenyuThreadFactory.create("shenyu_proxy_server_work_epoll", false));
-            server.channel(NioServerSocketChannel.class);
+        createEventLoopGroup(threads);
+        initServerBootstrap();
+        try {
+            Channel channel = server.bind(port).sync().channel();
+            logger.info("Network listening,ip:{},port:{}", 
((InetSocketAddress) channel.localAddress()).getHostString(), port);
+            channel.closeFuture().sync();
+        } catch (InterruptedException e) {
+            logger.error("Error Network listening...... " + e.getMessage());
+            throw new RuntimeException("Error Network listening " + 
e.getMessage());
+        } finally {
+            bossGroup.shutdownGracefully();
+            workerGroup.shutdownGracefully();
         }
+    }
+    
+    private void initServerBootstrap() {
         NettyServerHandler nettyServerHandler = new NettyServerHandler(this);
-        server.group(boosGroup, workGroup)
+        server.group(bossGroup, workerGroup)
+                .channel(Epoll.isAvailable() ? EpollServerSocketChannel.class 
: NioServerSocketChannel.class)
                 .option(ChannelOption.SO_BACKLOG, 65535)
                 .option(ChannelOption.SO_REUSEADDR, true)
                 .option(ChannelOption.SO_KEEPALIVE, true)
@@ -110,27 +118,12 @@ public class NettyServer extends AbstractServer {
                         channel.pipeline().addLast(nettyServerHandler);
                     }
                 });
-        //setup information
-        try {
-            Channel channel = server.bind(port).sync().channel();
-            logger.info("Network listening,ip:{},port:{}", 
((InetSocketAddress) channel.localAddress()).getHostString(), port);
-            channel.closeFuture().sync();
-        } catch (InterruptedException e) {
-            logger.error("Error Network listening...... " + e.getMessage());
-            throw new RuntimeException("Error Network listening " + 
e.getMessage());
-        } finally {
-            boosGroup.shutdownGracefully();
-            workGroup.shutdownGracefully();
-        }
     }
     
-    /**
-     * Determine whether it is a Linux operating system.
-     *
-     * @return the boolean
-     */
-    public static boolean isLinux() {
-        final String oS = System.getProperty("os.name").toLowerCase();
-        return oS.contains("linux");
+    private void createEventLoopGroup(final int workerThreads) {
+        ThreadFactory bossFactory = 
ShenyuThreadFactory.create("shenyu_proxy_server_boss_epoll", false);
+        bossGroup = Epoll.isAvailable() ? new EpollEventLoopGroup(1, 
bossFactory) : new NioEventLoopGroup(1, bossFactory);
+        ThreadFactory workerFactory = 
ShenyuThreadFactory.create("shenyu_proxy_server_work_epoll", false);
+        workerGroup = Epoll.isAvailable() ? new 
EpollEventLoopGroup(workerThreads, workerFactory) : new 
NioEventLoopGroup(workerThreads, workerFactory);
     }
 }
diff --git 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServerHandler.java
 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServerHandler.java
similarity index 99%
rename from 
shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServerHandler.java
rename to 
shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServerHandler.java
index 0a8a1b550..1354000ea 100644
--- 
a/shenyu-proxy/proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServerHandler.java
+++ 
b/shenyu-proxy/shenyu-proxy-remote/src/main/java/org/apache/shenyu/proxy/remote/netty/NettyServerHandler.java
@@ -110,5 +110,4 @@ public class NettyServerHandler extends 
ChannelDuplexHandler {
         NettyChannel channel = NettyChannel.getOrAddChannel(ctx.channel());
         channelHandler.caught(channel, cause);
     }
-    
 }
diff --git 
a/shenyu-proxy/proxy-remote/src/test/java/org/apache/shenyu/proxy/remote/NettyServerTest.java
 
b/shenyu-proxy/shenyu-proxy-remote/src/test/java/org/apache/shenyu/proxy/remote/NettyServerTest.java
similarity index 100%
rename from 
shenyu-proxy/proxy-remote/src/test/java/org/apache/shenyu/proxy/remote/NettyServerTest.java
rename to 
shenyu-proxy/shenyu-proxy-remote/src/test/java/org/apache/shenyu/proxy/remote/NettyServerTest.java

Reply via email to