Skip to content

Commit

Permalink
fix: support custom host header on request proto change (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Oct 27, 2022
1 parent df84eff commit b3fd35e
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 28 deletions.
18 changes: 0 additions & 18 deletions .vscode/launch.json

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -25,7 +25,7 @@ Proxyee is a JAVA written HTTP proxy server library that supports HTTP, HTTPS, W
<dependency>
<groupId>com.github.monkeywie</groupId>
<artifactId>proxyee</artifactId>
<version>1.6.9</version>
<version>1.7.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion README_zh-CN.md
Expand Up @@ -25,7 +25,7 @@ Proxyee 是一个 JAVA 编写的 HTTP 代理服务器类库,支持 HTTP、HTTP
<dependency>
<groupId>com.github.monkeywie</groupId>
<artifactId>proxyee</artifactId>
<version>1.6.9</version>
<version>1.7.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.monkeywie</groupId>
<artifactId>proxyee</artifactId>
<version>1.6.9</version>
<version>1.7.0</version>

<packaging>jar</packaging>

Expand Down
Expand Up @@ -287,13 +287,6 @@ private void handleProxyData(Channel channel, Object msg, boolean isHttp) throws
RequestProto newRP = ProtoUtil.getRequestProto(httpRequest);
if (!newRP.equals(pipeRp)) {
isChangeRp = true;
// 更新Host请求头
if ((pipeRp.getSsl() && pipeRp.getPort() == 443)
|| (!pipeRp.getSsl() && pipeRp.getPort() == 80)) {
httpRequest.headers().set(HttpHeaderNames.HOST, pipeRp.getHost());
} else {
httpRequest.headers().set(HttpHeaderNames.HOST, pipeRp.getHost() + ":" + pipeRp.getPort());
}
}
}

Expand Down
Expand Up @@ -8,6 +8,7 @@
import com.github.monkeywie.proxyee.server.HttpProxyServerConfig;
import com.github.monkeywie.proxyee.util.HttpUtil;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpRequest;

/**
Expand Down Expand Up @@ -37,6 +38,7 @@ public void beforeRequest(Channel clientChannel, HttpRequest httpRequest,
pipeline.getRequestProto().setHost("www.taobao.com");
pipeline.getRequestProto().setPort(443);
pipeline.getRequestProto().setSsl(true);
httpRequest.headers().set(HttpHeaderNames.HOST, "www.taobao.com");
}
pipeline.beforeRequest(clientChannel, httpRequest);
}
Expand Down

0 comments on commit b3fd35e

Please sign in to comment.