@@ -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