From 9717f66f826fc3d3e72430a0841d690adec2641f Mon Sep 17 00:00:00 2001 From: Harry Chan Date: Fri, 4 Oct 2024 17:23:58 +1000 Subject: [PATCH 1/2] Optimize header validation loop --- .../src/main/java/io/helidon/http/Header.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/http/http/src/main/java/io/helidon/http/Header.java b/http/http/src/main/java/io/helidon/http/Header.java index 45727acf8ae..d84ef61c0d0 100644 --- a/http/http/src/main/java/io/helidon/http/Header.java +++ b/http/http/src/main/java/io/helidon/http/Header.java @@ -86,14 +86,12 @@ default List allValues(boolean split) { String value = values.get(0); if (value.contains(", ")) { return List.of(value.split(", ")); - } else { - return List.of(value); } + return List.of(value); } return values; - } else { - return allValues(); } + return allValues(); } /** @@ -160,17 +158,17 @@ default void validate() throws IllegalArgumentException { private static void validateValue(String name, String value) throws IllegalArgumentException { char[] vChars = value.toCharArray(); int vLength = vChars.length; - for (int i = 0; i < vLength; i++) { - char vChar = vChars[i]; - if (i == 0) { - if (vChar < '!' || vChar == '\u007f') { - throw new IllegalArgumentException("First character of the header value is invalid" - + " for header '" + name + "'"); - } - } else { + if (vLength >= 1) { + char vChar = vChars[0]; + if (vChar < '!' || vChar == '\u007f') { + throw new IllegalArgumentException("First character of the header value is invalid" + + " for header '" + name + "'"); + } + for (int i = 1; i < vLength; i++) { + vChar = vChars[i]; if (vChar < ' ' && vChar != '\t' || vChar == '\u007f') { throw new IllegalArgumentException("Character at position " + (i + 1) + " of the header value is invalid" - + " for header '" + name + "'"); + + " for header '" + name + "'"); } } } From d05c9ec1472e64e7a2e59dd33192fc2de7ef53d5 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Fri, 18 Oct 2024 10:15:50 +0200 Subject: [PATCH 2/2] Copyright fix --- http/http/src/main/java/io/helidon/http/Header.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http/http/src/main/java/io/helidon/http/Header.java b/http/http/src/main/java/io/helidon/http/Header.java index d84ef61c0d0..73d6cd4055a 100644 --- a/http/http/src/main/java/io/helidon/http/Header.java +++ b/http/http/src/main/java/io/helidon/http/Header.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2023, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.