Skip to content

Commit 9ea00e7

Browse files
committed
use normalized header keys to avoid allocations
1 parent 0edf903 commit 9ea00e7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/main/java/robaho/net/httpserver/ServerImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ Logger getLogger() {
417417
}
418418

419419
private void closeConnection(HttpConnection conn) {
420-
logger.log(Level.TRACE, "closing connection: " + conn.toString());
420+
logger.log(Level.TRACE, () -> "closing connection: " + conn.toString());
421421
conn.close();
422422
allConnections.remove(conn);
423423
}
@@ -533,8 +533,8 @@ private void runPerRequest() throws IOException {
533533
// }
534534
// }
535535
/* checks for unsupported combinations of lengths and encodings */
536-
if (headers.containsKey("Content-Length")
537-
&& (headers.containsKey("Transfer-encoding") || headers.get("Content-Length").size() > 1)) {
536+
if (headers.containsKey("Content-length")
537+
&& (headers.containsKey("Transfer-encoding") || headers.get("Content-length").size() > 1)) {
538538
reject(Code.HTTP_BAD_REQUEST, requestLine,
539539
"Conflicting or malformed headers detected");
540540
return;
@@ -554,7 +554,7 @@ private void runPerRequest() throws IOException {
554554
return;
555555
}
556556
} else {
557-
headerValue = headers.getFirst("Content-Length");
557+
headerValue = headers.getFirst("Content-length");
558558
if (headerValue != null) {
559559
try {
560560
clen = Long.parseLong(headerValue);
@@ -599,7 +599,7 @@ private void runPerRequest() throws IOException {
599599
rheaders.set("Connection", "keep-alive");
600600
int idleSeconds = (int) (ServerConfig.getIdleIntervalMillis() / 1000);
601601
String val = "timeout=" + idleSeconds;
602-
rheaders.set("Keep-Alive", val);
602+
rheaders.set("Keep-alive", val);
603603
}
604604
}
605605

src/main/java/robaho/net/httpserver/websockets/Util.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@
4343

4444
public class Util {
4545

46-
public static final String HEADER_UPGRADE = "upgrade";
46+
public static final String HEADER_UPGRADE = "Upgrade";
4747

4848
public static final String HEADER_UPGRADE_VALUE = "websocket";
4949

50-
public static final String HEADER_CONNECTION = "connection";
50+
public static final String HEADER_CONNECTION = "Connection";
5151

5252
public static final String HEADER_CONNECTION_VALUE = "Upgrade";
5353

@@ -75,7 +75,7 @@ public static String makeAcceptKey(String key) throws NoSuchAlgorithmException {
7575
return encodeBase64(sha1hash);
7676
}
7777

78-
private static final String CONTENT_TYPE = "content-type";
78+
private static final String CONTENT_TYPE = "Content-type";
7979

8080
public static void sendResponseHeaders(HttpExchange exchange, int code, String reason) throws IOException {
8181
var bytes = reason.getBytes();

0 commit comments

Comments
 (0)