Reject negative Content-Length values in HttpHeaders
Prior to this commit, `HttpHeaders#setContentLength` would accept negative values. Those are not allowed by the RFC and the headers implementation only uses "-1" as a way to convey that no value was set. This commit ensures that negative values are rejected. Fixes gh-32660
This commit is contained in:
@@ -154,6 +154,17 @@ class HttpHeadersTests {
|
||||
assertThat(headers.getFirst("Content-Length")).as("Invalid Content-Length header").isEqualTo("42");
|
||||
}
|
||||
|
||||
@Test
|
||||
void setContentLengthWithNegativeValue() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
headers.setContentLength(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getContentLengthReturnsMinusOneForAbsentHeader() {
|
||||
assertThat(headers.getContentLength()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void contentType() {
|
||||
MediaType contentType = new MediaType("text", "html", StandardCharsets.UTF_8);
|
||||
|
||||
Reference in New Issue
Block a user