Skip to content

Commit

Permalink
Merge #2534 into 2.0.0-M2
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Oct 10, 2022
2 parents 8f54b98 + 981c5fd commit a433a81
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
Expand Up @@ -36,7 +36,6 @@
import io.netty5.channel.ChannelFutureListeners;
import io.netty5.channel.ChannelHandlerContext;
import io.netty5.channel.ChannelOption;
import io.netty5.handler.codec.TooLongFrameException;
import io.netty5.handler.codec.http.DefaultFullHttpResponse;
import io.netty5.handler.codec.http.DefaultHttpResponse;
import io.netty5.handler.codec.http.DefaultLastHttpContent;
Expand All @@ -58,6 +57,8 @@
import io.netty5.handler.codec.http.HttpUtil;
import io.netty5.handler.codec.http.HttpVersion;
import io.netty5.handler.codec.http.LastHttpContent;
import io.netty5.handler.codec.http.TooLongHttpHeaderException;
import io.netty5.handler.codec.http.TooLongHttpLineException;
import io.netty5.handler.codec.http.headers.HttpSetCookie;
import io.netty5.handler.codec.http.websocketx.CloseWebSocketFrame;
import io.netty5.handler.codec.http.websocketx.WebSocketCloseStatus;
Expand Down Expand Up @@ -723,9 +724,17 @@ static void sendDecodingFailures(

Resource.dispose(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,
ctx.bufferAllocator().allocate(0));
response.headers()
.set(HttpHeaderNames.CONTENT_LENGTH, HttpHeaderValues.ZERO)
Expand Down
Expand Up @@ -764,7 +764,7 @@ void testBadRequest(HttpProtocol[] serverProtocols, HttpProtocol[] clientProtoco
.uri("/max_header_size")
.responseSingle((res, bufferMono) -> Mono.just(res.status().code()))
.as(StepVerifier::create)
.expectNext(413)
.expectNext(431)
.expectComplete()
.verify(Duration.ofSeconds(30));

Expand Down Expand Up @@ -879,15 +879,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 @@ -909,7 +909,29 @@ private void doTestIssue309(String path, HttpServer httpServer) {
.responseSingle((res, bufferMono) -> 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

0 comments on commit a433a81

Please sign in to comment.