Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ghsby
o2oa
提交
45d95308
o2oa
项目概览
ghsby
/
o2oa
落后 Fork 源项目 2880 个版本
Fork自
浙江兰德纵横网络技术股份有限公司 / o2oa
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
o2oa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
45d95308
编写于
10月 14, 2020
作者:
Z
zhourui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改代理到本地127,0,0,1
上级
f2cb0e72
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
81 addition
and
5 deletion
+81
-5
o2server/x_console/src/main/java/com/x/server/console/server/web/Proxy.java
.../src/main/java/com/x/server/console/server/web/Proxy.java
+81
-5
未找到文件。
o2server/x_console/src/main/java/com/x/server/console/server/web/Proxy.java
浏览文件 @
45d95308
...
...
@@ -3,11 +3,14 @@ package com.x.server.console.server.web;
import
javax.servlet.http.HttpServletRequest
;
import
org.apache.commons.lang3.StringUtils
;
import
org.eclipse.jetty.client.api.Request
;
import
org.eclipse.jetty.http.HttpHeader
;
import
org.eclipse.jetty.proxy.AsyncProxyServlet
;
public
class
Proxy
extends
AsyncProxyServlet
{
private
static
final
long
serialVersionUID
=
2737360000716631564L
;
private
static
final
String
X_Real_IP
=
"X-Real-IP"
;
@Override
protected
String
rewriteTarget
(
HttpServletRequest
request
)
{
...
...
@@ -17,19 +20,30 @@ public class Proxy extends AsyncProxyServlet {
}
private
String
target
(
String
url
,
String
parameter
,
String
port
)
{
int
x
=
StringUtils
.
indexOf
(
url
,
":
"
,
8
);
int
x
=
StringUtils
.
indexOf
(
url
,
":
//"
);
int
y
=
StringUtils
.
indexOf
(
url
,
"/"
,
8
);
if
((
x
>
0
)
&&
(
y
>
0
))
{
return
url
.
substring
(
0
,
x
)
+
port
(
url
,
port
)
+
url
.
substring
(
y
)
+
(
StringUtils
.
isBlank
(
parameter
)
?
""
:
"?"
+
parameter
);
}
else
if
(
y
>
0
)
{
return
url
.
substring
(
0
,
y
)
+
port
(
url
,
port
)
+
url
.
substring
(
y
)
return
url
.
substring
(
0
,
x
+
3
)
+
"127.0.0.1"
+
port
(
url
,
port
)
+
url
.
substring
(
y
)
+
(
StringUtils
.
isBlank
(
parameter
)
?
""
:
"?"
+
parameter
);
}
else
{
return
null
;
}
}
// private String target(String url, String parameter, String port) {
// int x = StringUtils.indexOf(url, ":", 8);
// int y = StringUtils.indexOf(url, "/", 8);
// if ((x > 0) && (y > 0)) {
// return url.substring(0, x) + port(url, port) + url.substring(y)
// + (StringUtils.isBlank(parameter) ? "" : "?" + parameter);
// } else if (y > 0) {
// return url.substring(0, y) + port(url, port) + url.substring(y)
// + (StringUtils.isBlank(parameter) ? "" : "?" + parameter);
// } else {
// return null;
// }
// }
private
String
port
(
String
url
,
String
port
)
{
if
(
StringUtils
.
startsWithIgnoreCase
(
url
,
"https://"
)
||
StringUtils
.
startsWithIgnoreCase
(
url
,
"wss://"
))
{
if
(
StringUtils
.
equals
(
port
,
"443"
))
{
...
...
@@ -43,4 +57,66 @@ public class Proxy extends AsyncProxyServlet {
return
":"
+
port
;
}
@Override
protected
void
addXForwardedHeaders
(
HttpServletRequest
clientRequest
,
Request
proxyRequest
)
{
if
(
StringUtils
.
isNotEmpty
(
clientRequest
.
getHeader
(
HttpHeader
.
X_FORWARDED_FOR
.
asString
())))
{
proxyRequest
.
header
(
HttpHeader
.
X_FORWARDED_FOR
,
clientRequest
.
getHeader
(
HttpHeader
.
X_FORWARDED_FOR
.
asString
()));
}
else
{
proxyRequest
.
header
(
HttpHeader
.
X_FORWARDED_FOR
,
clientRequest
.
getRemoteAddr
());
}
if
(
StringUtils
.
isNotEmpty
(
clientRequest
.
getHeader
(
HttpHeader
.
X_FORWARDED_PROTO
.
asString
())))
{
proxyRequest
.
header
(
HttpHeader
.
X_FORWARDED_PROTO
,
clientRequest
.
getHeader
(
HttpHeader
.
X_FORWARDED_PROTO
.
asString
()));
}
else
{
proxyRequest
.
header
(
HttpHeader
.
X_FORWARDED_PROTO
,
clientRequest
.
getScheme
());
}
if
(
StringUtils
.
isNotEmpty
(
clientRequest
.
getHeader
(
HttpHeader
.
X_FORWARDED_HOST
.
asString
())))
{
proxyRequest
.
header
(
HttpHeader
.
X_FORWARDED_HOST
,
clientRequest
.
getHeader
(
HttpHeader
.
X_FORWARDED_HOST
.
asString
()));
}
else
{
proxyRequest
.
header
(
HttpHeader
.
X_FORWARDED_HOST
,
clientRequest
.
getHeader
(
HttpHeader
.
HOST
.
asString
()));
}
if
(
StringUtils
.
isNotEmpty
(
clientRequest
.
getHeader
(
HttpHeader
.
X_FORWARDED_SERVER
.
asString
())))
{
proxyRequest
.
header
(
HttpHeader
.
X_FORWARDED_SERVER
,
clientRequest
.
getHeader
(
HttpHeader
.
X_FORWARDED_SERVER
.
asString
()));
}
else
{
proxyRequest
.
header
(
HttpHeader
.
X_FORWARDED_SERVER
,
clientRequest
.
getLocalName
());
}
if
(
StringUtils
.
isNotEmpty
(
clientRequest
.
getHeader
(
HttpHeader
.
HOST
.
asString
())))
{
proxyRequest
.
header
(
HttpHeader
.
HOST
,
clientRequest
.
getHeader
(
HttpHeader
.
HOST
.
asString
()));
}
if
(
StringUtils
.
isNotEmpty
(
clientRequest
.
getHeader
(
X_Real_IP
)))
{
proxyRequest
.
header
(
X_Real_IP
,
clientRequest
.
getHeader
(
X_Real_IP
));
}
else
{
proxyRequest
.
header
(
X_Real_IP
,
clientRequest
.
getRemoteAddr
());
}
// if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.UPGRADE.asString()))) {
// proxyRequest.header(HttpHeader.UPGRADE, clientRequest.getHeader(HttpHeader.UPGRADE.asString()));
// }
//
// if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.CONNECTION.asString()))) {
// proxyRequest.header(HttpHeader.CONNECTION, clientRequest.getHeader(HttpHeader.CONNECTION.asString()));
// }
//
// if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS.asString()))) {
// proxyRequest.header(HttpHeader.SEC_WEBSOCKET_EXTENSIONS,
// clientRequest.getHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS.asString()));
// }
//
// if (StringUtils.isNotEmpty(clientRequest.getHeader(HttpHeader.SEC_WEBSOCKET_KEY.asString()))) {
// proxyRequest.header(HttpHeader.SEC_WEBSOCKET_KEY,
// clientRequest.getHeader(HttpHeader.SEC_WEBSOCKET_KEY.asString()));
// }
if
(
StringUtils
.
isNotEmpty
(
clientRequest
.
getHeader
(
HttpHeader
.
SEC_WEBSOCKET_VERSION
.
asString
())))
{
proxyRequest
.
header
(
HttpHeader
.
SEC_WEBSOCKET_VERSION
,
clientRequest
.
getHeader
(
HttpHeader
.
SEC_WEBSOCKET_VERSION
.
asString
()));
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录