Skip to content

Commit 47757a7

Browse files
committed
perf: 高并发时逐跳标头判定逻辑优化
1 parent b125f17 commit 47757a7

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

pom.xml

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

77
<groupId>top.meethigher</groupId>
88
<artifactId>tcp-reverse-proxy</artifactId>
9-
<version>1.0.2</version>
9+
<version>1.0.3</version>
1010

1111
<properties>
1212
<maven.compiler.source>8</maven.compiler.source>

src/main/java/top/meethigher/proxy/http/ReverseHttpProxy.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ public class ReverseHttpProxy {
178178
/**
179179
* 不应该被复制的逐跳标头
180180
*/
181-
protected final String[] hopByHopHeaders = new String[]{
182-
"Connection", "Keep-Alive", "Proxy-Authenticate", "Proxy-Authorization",
183-
"TE", "Trailers", "Transfer-Encoding", "Upgrade"};
181+
protected static final Set<String> HOP_BY_HOP_HEADERS_SET = new HashSet<>(Arrays.asList(
182+
"connection", "keep-alive", "proxy-authenticate", "proxy-authorization",
183+
"te", "trailers", "transfer-encoding", "upgrade"));
184184

185185
/**
186186
* 跨域相关的响应头
@@ -375,15 +375,15 @@ public List<Route> getRoutes() {
375375
}
376376

377377

378+
/**
379+
* 将标头转为小写后,判断是否是逐跳标头
380+
* 时间复杂度为 O(1)
381+
*/
378382
protected boolean isHopByHopHeader(String headerName) {
379-
for (String hopByHopHeader : hopByHopHeaders) {
380-
if (hopByHopHeader.equalsIgnoreCase(headerName)) {
381-
return true;
382-
}
383-
}
384-
return false;
383+
return headerName != null && HOP_BY_HOP_HEADERS_SET.contains(headerName.toLowerCase());
385384
}
386385

386+
387387
/**
388388
* 复制请求头。复制的过程中忽略逐跳标头
389389
*/

0 commit comments

Comments
 (0)