Skip to content

Commit

Permalink
Optimize header validation loop
Browse files Browse the repository at this point in the history
  • Loading branch information
re-thc authored and romain-grecourt committed Nov 27, 2024
1 parent b5759b3 commit 9717f66
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions http/http/src/main/java/io/helidon/http/Header.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,12 @@ default List<String> 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();
}

/**
Expand Down Expand Up @@ -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 + "'");
}
}
}
Expand Down

0 comments on commit 9717f66

Please sign in to comment.