-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return "431 Request Header Fields Too Large" for long headers on HTTP…
…/1 (#4655) * Return "431 Request Header Fields Too Large" for long headers on HTTP/1 Motivation: Netty HTTP/1 codec raises `TooLongHttpHeaderException` if headers exceed the max length limit. However, `Http1RequestDecoder` does not take account into `TooLongHttpLineException` and returns "400 Bad Request" instead. Modifications: - Make `Http1RequestDecoder` return `431 Request Header Fields Too Large` if a Netty HttpRequest fails with `TooLongHttpHeaderException` Result: - "431 Request Header Fields Too Large" is now returned instead of `400 Bad Request` if the size of header exceeds `ServerBuilder.http1MaxHeaderSize()`. - Fixes #4609 * Fix the error message
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
core/src/test/java/com/linecorp/armeria/server/LongHttp1HeadersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2023 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.linecorp.armeria.server; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.google.common.base.Strings; | ||
|
||
import com.linecorp.armeria.client.BlockingWebClient; | ||
import com.linecorp.armeria.common.AggregatedHttpResponse; | ||
import com.linecorp.armeria.common.HttpResponse; | ||
import com.linecorp.armeria.common.HttpStatus; | ||
import com.linecorp.armeria.common.SessionProtocol; | ||
import com.linecorp.armeria.testing.junit5.server.ServerExtension; | ||
|
||
class LongHttp1HeadersTest { | ||
|
||
@RegisterExtension | ||
static ServerExtension server = new ServerExtension() { | ||
@Override | ||
protected void configure(ServerBuilder sb) { | ||
sb.http1MaxHeaderSize(100); | ||
|
||
sb.service("/", (ctx, req) -> HttpResponse.of("OK")); | ||
} | ||
}; | ||
|
||
@Test | ||
void shouldReturn431WithLongHeadersForHttp1() { | ||
final BlockingWebClient client = BlockingWebClient.of(server.uri(SessionProtocol.H1C)); | ||
final AggregatedHttpResponse response = client.prepare() | ||
.get("/") | ||
.header("x-long", Strings.repeat("1", 100)) | ||
.execute(); | ||
assertThat(response.status()).isEqualTo(HttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE); | ||
} | ||
} |