Skip to content

Commit 493b74e

Browse files
authored
fix: forward connect keep alive issue (#228)
1 parent 3011f5b commit 493b74e

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.DS_Store/
2+
13
*.class
24

35
# BlueJ files

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Proxyee is a JAVA written HTTP proxy server library that supports HTTP, HTTPS, W
2525
<dependency>
2626
<groupId>com.github.monkeywie</groupId>
2727
<artifactId>proxyee</artifactId>
28-
<version>1.6.7</version>
28+
<version>1.6.8</version>
2929
</dependency>
3030
```
3131

README_zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Proxyee 是一个 JAVA 编写的 HTTP 代理服务器类库,支持 HTTP、HTTP
2525
<dependency>
2626
<groupId>com.github.monkeywie</groupId>
2727
<artifactId>proxyee</artifactId>
28-
<version>1.6.7</version>
28+
<version>1.6.8</version>
2929
</dependency>
3030
```
3131

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.github.monkeywie</groupId>
77
<artifactId>proxyee</artifactId>
8-
<version>1.6.7</version>
8+
<version>1.6.8</version>
99

1010
<packaging>jar</packaging>
1111

src/main/java/com/github/monkeywie/proxyee/handler/HttpProxyServerHandler.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,25 @@ private boolean authenticate(ChannelHandlerContext ctx, HttpRequest request) {
275275
}
276276

277277
private void handleProxyData(Channel channel, Object msg, boolean isHttp) throws Exception {
278-
if (getChannelFuture() == null) {
278+
RequestProto pipeRp = getInterceptPipeline().getRequestProto();
279+
boolean isChangeRp = false;
280+
if (isHttp && msg instanceof HttpRequest) {
281+
HttpRequest httpRequest = (HttpRequest) msg;
282+
// 检查requestProto是否有修改
283+
RequestProto newRP = ProtoUtil.getRequestProto(httpRequest);
284+
if (!newRP.equals(pipeRp)) {
285+
isChangeRp = true;
286+
// 更新Host请求头
287+
if ((pipeRp.getSsl() && pipeRp.getPort() == 443)
288+
|| (!pipeRp.getSsl() && pipeRp.getPort() == 80)) {
289+
httpRequest.headers().set(HttpHeaderNames.HOST, pipeRp.getHost());
290+
} else {
291+
httpRequest.headers().set(HttpHeaderNames.HOST, pipeRp.getHost() + ":" + pipeRp.getPort());
292+
}
293+
}
294+
}
295+
296+
if (isChangeRp || getChannelFuture() == null) {
279297
// connection异常 还有HttpContent进来,不转发
280298
if (isHttp && !(msg instanceof HttpRequest)) {
281299
return;
@@ -290,22 +308,6 @@ private void handleProxyData(Channel channel, Object msg, boolean isHttp) throws
290308
ProxyHandler proxyHandler = ProxyHandleFactory.build(getInterceptPipeline().getProxyConfig() == null ?
291309
proxyConfig : getInterceptPipeline().getProxyConfig());
292310

293-
RequestProto pipeRp = getInterceptPipeline().getRequestProto();
294-
if (isHttp) {
295-
HttpRequest httpRequest = (HttpRequest) msg;
296-
// 检查requestProto是否有修改
297-
RequestProto newRP = ProtoUtil.getRequestProto(httpRequest);
298-
if (!newRP.equals(pipeRp)) {
299-
// 更新Host请求头
300-
if ((pipeRp.getSsl() && pipeRp.getPort() == 443)
301-
|| (!pipeRp.getSsl() && pipeRp.getPort() == 80)) {
302-
httpRequest.headers().set(HttpHeaderNames.HOST, pipeRp.getHost());
303-
} else {
304-
httpRequest.headers().set(HttpHeaderNames.HOST, pipeRp.getHost() + ":" + pipeRp.getPort());
305-
}
306-
}
307-
}
308-
309311
/*
310312
* 添加SSL client hello的Server Name Indication extension(SNI扩展) 有些服务器对于client
311313
* hello不带SNI扩展时会直接返回Received fatal alert: handshake_failure(握手错误)

0 commit comments

Comments
 (0)