Full header support HTTP HEAD Resource requests

Allow the body to be written in order for all headers to be set
as they would be on HTTP GET. The body content is ignored as a
lower level.

See gh-25976
This commit is contained in:
Rossen Stoyanchev
2020-10-27 11:14:37 +00:00
parent d91b66a04c
commit bb4e802af5
4 changed files with 14 additions and 14 deletions

View File

@@ -118,7 +118,6 @@ public class ResourceHttpRequestHandlerTests {
assertThat(this.response.getDateHeader("Last-Modified") / 1000).isEqualTo(resourceLastModified("test/foo.css") / 1000);
assertThat(this.response.getHeader("Accept-Ranges")).isEqualTo("bytes");
assertThat(this.response.getHeaders("Accept-Ranges").size()).isEqualTo(1);
assertThat(this.response.getContentAsByteArray().length).isEqualTo(0);
}
@Test
@@ -686,6 +685,20 @@ public class ResourceHttpRequestHandlerTests {
assertThat(this.response.getHeaderValues("Vary")).containsExactly("Accept-Encoding");
}
@Test // gh-25976
public void partialContentWithHttpHead() throws Exception {
this.request.setMethod("HEAD");
this.request.addHeader("Range", "bytes=0-1");
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.txt");
this.handler.handleRequest(this.request, this.response);
assertThat(this.response.getStatus()).isEqualTo(206);
assertThat(this.response.getContentType()).isEqualTo("text/plain");
assertThat(this.response.getContentLength()).isEqualTo(2);
assertThat(this.response.getHeader("Content-Range")).isEqualTo("bytes 0-1/10");
assertThat(this.response.getHeaderValues("Accept-Ranges")).containsExactly("bytes");
}
@Test // SPR-14005
public void doOverwriteExistingCacheControlHeaders() throws Exception {
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.css");