Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions java/org/apache/tomcat/util/http/parser/HttpHeaderParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,13 @@ public HeaderParseStatus parseHeader() throws IOException {
} else {
// Replace the line folding with a single space as required
// by RFC 9112 section 5.2. Any further whitespace at the
// start of the continuation line is skipped below.
source.getHeaderByteBuffer().put(headerData.realPos, SP);
headerData.realPos++;
// start of the continuation line is skipped below. A fold
// before the value is leading whitespace, which is not part
// of the field value (RFC 9110 section 5.5).
if (headerData.realPos > headerData.start) {
source.getHeaderByteBuffer().put(headerData.realPos, SP);
headerData.realPos++;
}
headerParsePos = HeaderParsePosition.HEADER_VALUE_START;
}
}
Expand Down
31 changes: 30 additions & 1 deletion test/org/apache/coyote/http11/TestHttp11InputBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,35 @@ public boolean isResponseBodyOK() {
}


@Test
public void testObsFoldBeforeValue() {
// RFC 9110, section 5.5: leading whitespace is not part of the field value
doTestObsFoldBeforeValue("X-Bug51557Fold:" + CRLF + " one", "oneabcd");
}


@Test
public void testObsFoldBeforeValueWithSpace() {
doTestObsFoldBeforeValue("X-Bug51557Fold: " + CRLF + "\t one", "oneabcd");
}


@Test
public void testObsFoldOnlyWhitespace() {
doTestObsFoldBeforeValue("X-Bug51557Fold:" + CRLF + " ", "abcd");
}


private void doTestObsFoldBeforeValue(String headerLine, String expected) {
Bug51557Client client = new Bug51557Client("X-Bug51557Fold");
client.headerLine = headerLine;

client.doRequest();
Assert.assertTrue(client.isResponse200());
Assert.assertEquals(expected, client.getResponseBody());
}


@Test
public void testBug51557Valid() {

Expand Down Expand Up @@ -355,7 +384,7 @@ private void doTestBug51557ValidCharInValue(char s) {
private class Bug51557Client extends SimpleHttpClient {

private final String headerName;
private final String headerLine;
private String headerLine;

Bug51557Client(String headerName) {
this.headerName = headerName;
Expand Down
Loading