Skip to content

Commit

Permalink
Return proper response code when an HTTP request contains an invalid …
Browse files Browse the repository at this point in the history
…Q value

Closes: quarkusio#27852
  • Loading branch information
geoand authored and Alasdair Preston committed Sep 14, 2022
1 parent af22e7c commit 1bfd5e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ private static float getQTypeWithParamInfo(MediaType type, String parameterName)
return rtn;
}
} catch (NumberFormatException e) {
throw new RuntimeException(String.format("Media type %s value must be a float: %s", parameterName, type), e);
throw new WebApplicationException(
String.format("Media type %s value must be a float: %s", parameterName, type),
Response.Status.BAD_REQUEST);
}
}
return 2.0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ public void testMatch() throws Exception {
response.close();
}

@Test
@DisplayName("Test Invalid Q Value")
public void testInvalidQValue() throws Exception {
WebTarget base = client.target(generateURL("/match"));
Response response = base.request()
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=malformed")
.get();
Assertions.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
response.close();
}

public void generalPostTest(String uri, String value) {
WebTarget base = client.target(uri);
Response response = base.request().get();
Expand Down

0 comments on commit 1bfd5e5

Please sign in to comment.