Skip to content

Commit b018306

Browse files
committed
提交自定义OutboundHandler
1 parent 30e6ff6 commit b018306

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

02nio/nio02/src/main/java/io/github/kimmking/gateway/outbound/myselfhttpclient/MyHttpOutboundHandler.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.http.impl.client.CloseableHttpClient;
1414
import org.apache.http.impl.client.HttpClients;
1515
import org.apache.http.util.EntityUtils;
16+
import org.hibernate.validator.internal.util.stereotypes.ThreadSafe;
1617
import org.springframework.util.StringUtils;
1718

1819
import 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

Comments
 (0)