@Override public void sendRedirect(String url) throws IOException { Assert.state(!isCommitted(), "Cannot send redirect - response is already committed"); Assert.notNull(url, "Redirect URL must not be null"); setHeader(HttpHeaders.LOCATION, url); setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); setCommitted(true); }
@Test // SPR-17330 public void matchDateFormattedWithHttpHeaders() throws Exception { long epochMilli = ZonedDateTime.of(2018, 10, 5, 0, 0, 0, 0, ZoneId.of("GMT")).toInstant().toEpochMilli(); HttpHeaders headers = new HttpHeaders(); headers.setDate("myDate", epochMilli); this.response.setHeader("d", headers.getFirst("myDate")); this.matchers.dateValue("d", epochMilli).match(this.mvcResult); }
@Test public void locationHeaderUpdatesGetRedirectedUrl() { String redirectUrl = "/redirect"; response.setHeader("Location", redirectUrl); assertEquals(redirectUrl, response.getRedirectedUrl()); }
@Test(expected = IllegalArgumentException.class) public void getInvalidDateHeader() { response.setHeader("Last-Modified", "invalid"); assertEquals("invalid", response.getHeader("Last-Modified")); response.getDateHeader("Last-Modified"); }
@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 // SPR-12677 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()); }
@Override public void sendRedirect(String url) throws IOException { Assert.state(!isCommitted(), "Cannot send redirect - response is already committed"); Assert.notNull(url, "Redirect URL must not be null"); setHeader(HttpHeaders.LOCATION, url); setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); setCommitted(true); }
@Override public void sendRedirect(String url) throws IOException { if (isCommitted()) { throw new IllegalStateException("Cannot send redirect - response is already committed"); } Assert.notNull(url, "Redirect URL must not be null"); setHeader(LOCATION_HEADER, url); setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); setCommitted(true); }