Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HTTP errors 414 and 431 #2534

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -153,6 +153,6 @@ public void testBadRequest() throws IOException {

this.get("/request_line_too_long");

assertThat(testSpanHandler.takeRemoteSpanWithErrorTag(SERVER, "413").tags()).containsEntry("error", "413");
assertThat(testSpanHandler.takeRemoteSpanWithErrorTag(SERVER, "414").tags()).containsEntry("error", "414");
}
}
Expand Up @@ -38,7 +38,6 @@
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.DefaultHeaders;
import io.netty.handler.codec.TooLongFrameException;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http.DefaultHttpResponse;
Expand All @@ -58,6 +57,8 @@
import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.codec.http.TooLongHttpHeaderException;
import io.netty.handler.codec.http.TooLongHttpLineException;
import io.netty.handler.codec.http.cookie.Cookie;
import io.netty.handler.codec.http.cookie.ServerCookieDecoder;
import io.netty.handler.codec.http.cookie.ServerCookieEncoder;
Expand Down Expand Up @@ -750,9 +751,17 @@ static void sendDecodingFailures(

ReferenceCountUtil.release(msg);

HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
cause instanceof TooLongFrameException ? HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE :
HttpResponseStatus.BAD_REQUEST);
final HttpResponseStatus status;
if (cause instanceof TooLongHttpLineException) {
status = HttpResponseStatus.REQUEST_URI_TOO_LONG;
}
else if (cause instanceof TooLongHttpHeaderException) {
status = HttpResponseStatus.REQUEST_HEADER_FIELDS_TOO_LARGE;
}
else {
status = HttpResponseStatus.BAD_REQUEST;
}
HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status);
response.headers()
.setInt(HttpHeaderNames.CONTENT_LENGTH, 0)
.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
Expand Down
Expand Up @@ -766,7 +766,7 @@ void testBadRequest(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtoco
.uri("/max_header_size")
.responseSingle((res, byteBufMono) -> Mono.just(res.status().code()))
.as(StepVerifier::create)
.expectNext(413)
.expectNext(431)
.expectComplete()
.verify(Duration.ofSeconds(30));

Expand Down Expand Up @@ -881,15 +881,15 @@ private void checkExpectationsNonExisting(String serverAddress, int connIndex, i

private void checkExpectationsBadRequest(String serverAddress, boolean checkTls) {
String uri = "/max_header_size";
String[] timerTags1 = new String[] {URI, uri, METHOD, "GET", STATUS, "413"};
String[] timerTags1 = new String[] {URI, uri, METHOD, "GET", STATUS, "431"};
String[] summaryTags1 = new String[] {URI, uri};

checkTimer(SERVER_RESPONSE_TIME, timerTags1, 1);
checkTimer(SERVER_DATA_SENT_TIME, timerTags1, 1);
checkDistributionSummary(SERVER_DATA_SENT, summaryTags1, 1, 0);
checkCounter(SERVER_ERRORS, summaryTags1, false, 0);

timerTags1 = new String[] {REMOTE_ADDRESS, serverAddress, URI, uri, METHOD, "GET", STATUS, "413"};
timerTags1 = new String[] {REMOTE_ADDRESS, serverAddress, URI, uri, METHOD, "GET", STATUS, "431"};
String[] timerTags2 = new String[] {REMOTE_ADDRESS, serverAddress, URI, uri, METHOD, "GET"};
String[] timerTags3 = new String[] {REMOTE_ADDRESS, serverAddress, STATUS, "SUCCESS"};
summaryTags1 = new String[] {REMOTE_ADDRESS, serverAddress, URI, uri};
Expand Down
Expand Up @@ -923,7 +923,29 @@ private void doTestIssue309(String path, HttpServer httpServer) {
.responseSingle((res, byteBufMono) -> Mono.just(res.status()));

StepVerifier.create(status)
.expectNextMatches(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE::equals)
.expectNextMatches(HttpResponseStatus.REQUEST_URI_TOO_LONG::equals)
.expectComplete()
.verify();
}

@Test
void httpServerRequestHeadersTooLong() {
HttpServer httpServer = HttpServer.create()
.port(0)
.httpRequestDecoder(c -> c.maxHeaderSize(20));
disposableServer =
httpServer.handle((req, res) -> res.sendString(Mono.just("Should not be reached")))
.bindNow();

Mono<HttpResponseStatus> status =
createClient(disposableServer.port())
.headers(h -> h.set("content-type", "somethingtooolooong"))
.get()
.uri("/path")
.responseSingle((res, byteBufMono) -> Mono.just(res.status()));

StepVerifier.create(status)
.expectNextMatches(HttpResponseStatus.REQUEST_HEADER_FIELDS_TOO_LARGE::equals)
.expectComplete()
.verify();
}
Expand Down