From 8bbd8d000d4defa793dd16ca7e59a24d1c7c10eb Mon Sep 17 00:00:00 2001 From: suxiang <2585546823@qq.com> Date: Wed, 18 Sep 2024 22:43:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E5=90=8E=EF=BC=8C=E5=B7=B2=E5=BB=BA=E7=AB=8B?= =?UTF-8?q?=E7=9A=84=E9=80=9A=E9=81=93=E4=BB=8D=E7=84=B6=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HttpVisitorSecurityChannelHandler.java | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/security/HttpVisitorSecurityChannelHandler.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/security/HttpVisitorSecurityChannelHandler.java index e541fa75..e817dfe3 100644 --- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/security/HttpVisitorSecurityChannelHandler.java +++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/security/HttpVisitorSecurityChannelHandler.java @@ -1,6 +1,5 @@ package org.dromara.neutrinoproxy.server.proxy.security; -import com.google.errorprone.annotations.Var; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; @@ -36,33 +35,32 @@ public class HttpVisitorSecurityChannelHandler extends ChannelInboundHandlerAdap public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; + // 获取Host请求头 + byte[] bytes = new byte[buf.readableBytes()]; + buf.readBytes(bytes); + String httpContent = new String(bytes); + String host = HttpUtil.getHostIgnorePort(httpContent); //test1.asgc.fun + + log.debug("HttpProxy host: {}", host); + if (StringUtils.isBlank(host)) { + ctx.channel().close(); + return; + } + // 判断域名是否被禁用或删除 + Integer domainNameId = ProxyUtil.getDomainNameIdByFullDomain(host); + if (domainNameId == null) { + ctx.channel().close(); + return; + } + // 域名映射强制https验证 + if (!isHttps && domainService.isOnlyHttps(domainNameId)) { + ctx.channel().close(); + return; + } + Integer serverPort = ctx.channel().attr(Constants.SERVER_PORT).get(); if (null == serverPort) { - // 获取Host请求头 - byte[] bytes = new byte[buf.readableBytes()]; - buf.readBytes(bytes); - String httpContent = new String(bytes); - String host = HttpUtil.getHostIgnorePort(httpContent); //test1.asgc.fun - - log.debug("HttpProxy host: {}", host); - if (StringUtils.isBlank(host)) { - ctx.channel().close(); - return; - } -// int index = host.lastIndexOf("." + domainName); -// String subdomain = host.substring(0, index); - // 判断域名是否被禁用或删除 - Integer domainNameId = ProxyUtil.getDomainNameIdByFullDomain(host); - if (domainNameId == null) { - ctx.channel().close(); - return; - } - // 域名映射强制https验证 - if (!isHttps && domainService.isOnlyHttps(domainNameId)) { - ctx.channel().close(); - return; - } - // 根据完整域名拿到服务端端口 + // channel没有服务器端口信息,尝试根据完整域名拿到服务端端口 serverPort = ProxyUtil.getServerPortByFullDomain(host); if (null == serverPort) { ctx.channel().close();