You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "arturobernalg (via GitHub)" <gi...@apache.org> on 2023/10/01 20:59:17 UTC
[GitHub] [httpcomponents-core] arturobernalg commented on a diff in pull request #437: HTTPCORE-756: replace CR, LF, NULL in header values with SP per RFC 9110 section 5.5
arturobernalg commented on code in PR #437:
URL: https://github.com/apache/httpcomponents-core/pull/437#discussion_r1342183980
##########
httpcore5/src/main/java/org/apache/hc/core5/http/message/BufferedHeader.java:
##########
@@ -110,7 +113,27 @@ public String getName() {
@Override
public String getValue() {
- return this.buffer.substringTrimmed(this.valuePos, this.buffer.length());
+ if (value == null) {
+ int beginIdx = valuePos;
+ int endIdx = buffer.length();
+ while (beginIdx < buffer.length() && Tokenizer.isWhitespace(buffer.charAt(beginIdx))) {
+ beginIdx++;
+ }
+ while (endIdx > beginIdx && Tokenizer.isWhitespace(buffer.charAt(endIdx - 1))) {
+ endIdx--;
+ }
+ final StringBuilder buf = new StringBuilder(endIdx - beginIdx);
+ for (int i = beginIdx; i < endIdx; i++) {
+ final char ch = buffer.charAt(i);
+ if (ch == Chars.CR || ch == Chars.LF || ch == 0) {
+ buf.append(' ');
Review Comment:
Using `(char) Chars.SP` instead of ' ' should not degrade the performance and would be clearer.
##########
httpcore5/src/main/java/org/apache/hc/core5/http/message/BufferedHeader.java:
##########
@@ -110,7 +113,27 @@ public String getName() {
@Override
public String getValue() {
- return this.buffer.substringTrimmed(this.valuePos, this.buffer.length());
+ if (value == null) {
+ int beginIdx = valuePos;
+ int endIdx = buffer.length();
+ while (beginIdx < buffer.length() && Tokenizer.isWhitespace(buffer.charAt(beginIdx))) {
+ beginIdx++;
+ }
+ while (endIdx > beginIdx && Tokenizer.isWhitespace(buffer.charAt(endIdx - 1))) {
+ endIdx--;
+ }
+ final StringBuilder buf = new StringBuilder(endIdx - beginIdx);
+ for (int i = beginIdx; i < endIdx; i++) {
+ final char ch = buffer.charAt(i);
+ if (ch == Chars.CR || ch == Chars.LF || ch == 0) {
Review Comment:
@ok2c Shouldn't add `public static final int NUL = 0; // <US-ASCII NUL, null (0)>` ??
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org