1313import org .apache .http .impl .client .CloseableHttpClient ;
1414import org .apache .http .impl .client .HttpClients ;
1515import org .apache .http .util .EntityUtils ;
16+ import org .hibernate .validator .internal .util .stereotypes .ThreadSafe ;
1617import org .springframework .util .StringUtils ;
1718
1819import java .io .IOException ;
@@ -34,7 +35,6 @@ public MyHttpOutboundHandler(String backendUrl) {
3435 client = HttpClients .createDefault ();
3536 proxyService = ThreadPool .getThreadPoolExecutor ();
3637 }
37-
3838 public void handler (FullHttpRequest fullRequest , ChannelHandlerContext ctx ) {
3939 final String url = this .backendUrl + fullRequest .uri ();
4040 if (StringUtils .isEmpty (url )) {
@@ -48,13 +48,13 @@ public void handler(FullHttpRequest fullRequest, ChannelHandlerContext ctx) {
4848 .setConnectionRequestTimeout (1000 ) // 连接请求超时时间
4949 .setSocketTimeout (1000 ) // 套接字超时时间
5050 .build ();
51- // HttpHeaders httpHeaders = fullRequest.headers();
52- // List<Map.Entry<String, String>> headerList = httpHeaders.entries();
51+ HttpHeaders httpHeaders = fullRequest .headers ();
52+ List <Map .Entry <String , String >> headerList = httpHeaders .entries ();
5353 // 设置全部请求头到对后端调用的请求头中
54- // headerList.forEach(header -> {
55- // Map.Entry<String, String> map = header;
56- // httpGet.addHeader(map.getKey(), map.getValue());
57- // });
54+ headerList .forEach (header -> {
55+ Map .Entry <String , String > map = header ;
56+ httpGet .addHeader (map .getKey (), map .getValue ());
57+ });
5858 httpGet .setConfig (config );
5959 proxyService .submit (() -> doGet (httpGet , fullRequest , ctx ));
6060 }
0 commit comments