@Test public void httpHeaderNameCasingIsPreserved() throws Exception { final String headerName = "Header1"; response.addHeader(headerName, "value1"); Collection<String> responseHeaders = response.getHeaderNames(); assertNotNull(responseHeaders); assertEquals(1, responseHeaders.size()); assertEquals( "HTTP header casing not being preserved", headerName, responseHeaders.iterator().next()); }
@Test public void contentTypeHeaderWithMoreComplexCharsetSyntax() { String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar"; response.setHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals("UTF-8", response.getCharacterEncoding()); response = new MockHttpServletResponse(); response.addHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals("UTF-8", response.getCharacterEncoding()); }
@Test public void contentTypeHeaderUTF8() { String contentType = "test/plain;charset=UTF-8"; response.setHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals("UTF-8", response.getCharacterEncoding()); response = new MockHttpServletResponse(); response.addHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals("UTF-8", response.getCharacterEncoding()); }
@Test public void contentTypeHeader() { String contentType = "test/plain"; response.addHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding()); response = new MockHttpServletResponse(); response.setHeader("Content-Type", contentType); assertEquals(contentType, response.getContentType()); assertEquals(contentType, response.getHeader("Content-Type")); assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding()); }
@Test public void contentLengthHeader() { response.addHeader("Content-Length", "66"); assertEquals(66, response.getContentLength()); assertEquals("66", response.getHeader("Content-Length")); }