From b677460110b6e86144e8b224847f69e03a74cac3 Mon Sep 17 00:00:00 2001 From: Konstantin Pelz Date: Fri, 18 Oct 2024 10:31:27 +0200 Subject: [PATCH] Always return a 415 if the content type is mismatching, also if its value is empty (#2659) * Always return a 415 if the content type is mismatching, also if its value isempty * Update RouterTest to expect 415 for missing content type --- .../src/main/java/io/vertx/ext/web/impl/RouteState.java | 6 +----- vertx-web/src/test/java/io/vertx/ext/web/RouterTest.java | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/vertx-web/src/main/java/io/vertx/ext/web/impl/RouteState.java b/vertx-web/src/main/java/io/vertx/ext/web/impl/RouteState.java index 9221b2ab7c..06acd2b0ef 100644 --- a/vertx-web/src/main/java/io/vertx/ext/web/impl/RouteState.java +++ b/vertx-web/src/main/java/io/vertx/ext/web/impl/RouteState.java @@ -1096,11 +1096,7 @@ public int matches(RoutingContextImplBase context, String mountPoint, boolean fa MIMEHeader contentType = context.parsedHeaders().contentType(); MIMEHeader consumal = contentType.findMatchedBy(consumes); if (consumal == null && !(contentType.rawValue().isEmpty() && emptyBodyPermittedWithConsumes)) { - if (contentType.rawValue().isEmpty()) { - return 400; - } else { - return 415; - } + return 415; } } if (!isEmpty(produces)) { diff --git a/vertx-web/src/test/java/io/vertx/ext/web/RouterTest.java b/vertx-web/src/test/java/io/vertx/ext/web/RouterTest.java index f48a39c8bb..7a4b11247b 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/RouterTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/RouterTest.java @@ -1168,7 +1168,7 @@ public void testConsumesCTParamsIgnored() throws Exception { @Test public void testConsumesNoContentType() throws Exception { router.route().consumes("text/html").handler(rc -> rc.response().end()); - testRequest(HttpMethod.GET, "/foo", HttpResponseStatus.BAD_REQUEST); + testRequest(HttpMethod.GET, "/foo", HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE); } @Test