From fa0ce6e7e1afc82986002acf1ca8c8ab2d833cc1 Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Tue, 6 Dec 2022 10:27:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=89=E9=92=89=E5=AF=B9=E6=8E=A5domain=20ht?= =?UTF-8?q?tps=E5=89=8D=E7=BC=80=E9=97=AE=E9=A2=98=E3=80=90issues/I5WRIN?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/common/util/SpringContextUtils.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/SpringContextUtils.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/SpringContextUtils.java index cd3d8783..f9d67869 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/SpringContextUtils.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/SpringContextUtils.java @@ -1,8 +1,6 @@ package org.jeecg.common.util; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.ServiceNameConstants; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; @@ -11,6 +9,9 @@ import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + /** * @Description: spring上下文工具类 * @author: jeecg-boot @@ -56,12 +57,19 @@ public class SpringContextUtils implements ApplicationContextAware { public static String getDomain(){ HttpServletRequest request = getHttpServletRequest(); StringBuffer url = request.getRequestURL(); - //微服务情况下,获取gateway的basePath + //1.微服务情况下,获取gateway的basePath String basePath = request.getHeader(ServiceNameConstants.X_GATEWAY_BASE_PATH); if(oConvertUtils.isNotEmpty(basePath)){ return basePath; }else{ - return url.delete(url.length() - request.getRequestURI().length(), url.length()).toString(); + String domain = url.delete(url.length() - request.getRequestURI().length(), url.length()).toString(); + //2.【兼容】SSL认证之后,request.getScheme()获取不到https的问题 + // https://blog.csdn.net/weixin_34376986/article/details/89767950 + String scheme = request.getHeader(CommonConstant.X_FORWARDED_SCHEME); + if(scheme!=null && !request.getScheme().equals(scheme)){ + domain = domain.replace(request.getScheme(),scheme); + } + return domain; } }