public boolean containsHeader(String name) { return resp.containsHeader(name); }
private void maybeSetLastModified(HttpServletResponse resp, long lastModified) { if (resp.containsHeader(HEADER_LASTMOD)) return; if (lastModified >= 0) resp.setDateHeader(HEADER_LASTMOD, lastModified); }
/** * @param arg0 * @return * @see javax.servlet.http.HttpServletResponse#containsHeader(java.lang.String) */ @Override public boolean containsHeader(String arg0) { return response.containsHeader(arg0); }
private void addSecureHeader(HttpServletResponse response, String securityHeader, String value) { if (!response.containsHeader(securityHeader)) { response.setHeader(securityHeader, value); } }
/** * Set the HTTP Cache-Control header according to the given settings. * @param response current HTTP response * @param cacheControl the pre-configured cache control settings * @since 4.2 */ protected final void applyCacheControl(HttpServletResponse response, CacheControl cacheControl) { String ccValue = cacheControl.getHeaderValue(); if (ccValue != null) { // Set computed HTTP 1.1 Cache-Control header response.setHeader(HEADER_CACHE_CONTROL, ccValue); if (response.containsHeader(HEADER_PRAGMA)) { // Reset HTTP 1.0 Pragma header if present response.setHeader(HEADER_PRAGMA, ""); } if (response.containsHeader(HEADER_EXPIRES)) { // Reset HTTP 1.0 Expires header if present response.setHeader(HEADER_EXPIRES, ""); } } }
else if (response.containsHeader(HEADER_EXPIRES)) { if (response.containsHeader(HEADER_PRAGMA)) {
private Collection<String> getVaryRequestHeadersToAdd(HttpServletResponse response, String[] varyByRequestHeaders) { if (!response.containsHeader(HttpHeaders.VARY)) { return Arrays.asList(varyByRequestHeaders); } Collection<String> result = new ArrayList<>(varyByRequestHeaders.length); Collections.addAll(result, varyByRequestHeaders); for (String header : response.getHeaders(HttpHeaders.VARY)) { for (String existing : StringUtils.tokenizeToStringArray(header, ",")) { if ("*".equals(existing)) { return Collections.emptyList(); } for (String value : varyByRequestHeaders) { if (value.equalsIgnoreCase(existing)) { result.remove(value); } } } } return result; }
/** * The default behavior of this method is to call containsHeader(String name) * on the wrapped response object. */ public boolean containsHeader(String name) { return this._getHttpServletResponse().containsHeader(name); }
@Override public boolean containsHeader(String name) { return !delegateToNativeResponse ? (headers.get(name) == null ? false : true) : _r().containsHeader(name); }
@Override protected void preResponseCommit() { long lastModified = lastModifiedData.getLastModified(); long ifModifiedSince = request.getDateHeader("If-Modified-Since"); if (lastModified > -1 && !response.containsHeader("Last-Modified")) { if (ifModifiedSince < (lastModified / 1000 * 1000)) { response.setDateHeader("Last-Modified", lastModified); } else { response.reset(); response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); } } } }
/** * Set the HTTP Cache-Control header according to the given settings. * @param response current HTTP response * @param cacheControl the pre-configured cache control settings * @since 4.2 */ protected final void applyCacheControl(HttpServletResponse response, CacheControl cacheControl) { String ccValue = cacheControl.getHeaderValue(); if (ccValue != null) { // Set computed HTTP 1.1 Cache-Control header response.setHeader(HEADER_CACHE_CONTROL, ccValue); if (response.containsHeader(HEADER_PRAGMA)) { // Reset HTTP 1.0 Pragma header if present response.setHeader(HEADER_PRAGMA, ""); } if (response.containsHeader(HEADER_EXPIRES)) { // Reset HTTP 1.0 Expires header if present response.setHeader(HEADER_EXPIRES, ""); } } }
private Collection<String> getVaryRequestHeadersToAdd(HttpServletResponse response, String[] varyByRequestHeaders) { if (!response.containsHeader(HttpHeaders.VARY)) { return Arrays.asList(varyByRequestHeaders); } Collection<String> result = new ArrayList<>(varyByRequestHeaders.length); Collections.addAll(result, varyByRequestHeaders); for (String header : response.getHeaders(HttpHeaders.VARY)) { for (String existing : StringUtils.tokenizeToStringArray(header, ",")) { if ("*".equals(existing)) { return Collections.emptyList(); } for (String value : varyByRequestHeaders) { if (value.equalsIgnoreCase(existing)) { result.remove(value); } } } } return result; }
/** * Delegate OPTIONS requests to {@link #processRequest}, if desired. * <p>Applies HttpServlet's standard OPTIONS processing otherwise, * and also if there is still no 'Allow' header set after dispatching. * @see #doService */ @Override protected void doOptions(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (this.dispatchOptionsRequest || CorsUtils.isPreFlightRequest(request)) { processRequest(request, response); if (response.containsHeader("Allow")) { // Proper OPTIONS response coming from a handler - we're done. return; } } // Use response wrapper in order to always add PATCH to the allowed methods super.doOptions(request, new HttpServletResponseWrapper(response) { @Override public void setHeader(String name, String value) { if ("Allow".equals(name)) { value = (StringUtils.hasLength(value) ? value + ", " : "") + HttpMethod.PATCH.name(); } super.setHeader(name, value); } }); }
@Test void testPreResponseCommit() { // setup decoraResponseWrapper = new DecoraResponseWrapper(originalRequest, originalResponse, lastModifiedData, decoraManager); when(lastModifiedData.getLastModified()).thenReturn(Long.valueOf(1)); when(originalResponse.containsHeader("Last-Modified")).thenReturn(true); // when decoraResponseWrapper.preResponseCommit(); // then verify(originalResponse, never()).setDateHeader("Last-Modified", 1); verify(originalResponse, never()).reset(); verify(originalResponse).containsHeader("Last-Modified"); }
@Test void testPreResponseCommit5() { // setup decoraResponseWrapper = new DecoraResponseWrapper(originalRequest, originalResponse, lastModifiedData, decoraManager); when(lastModifiedData.getLastModified()).thenReturn(Long.valueOf(1)); when(originalResponse.containsHeader("Last-Modified")).thenReturn(false); when(originalRequest.getDateHeader("If-Modified-Since")).thenReturn(Long.MAX_VALUE); // when decoraResponseWrapper.preResponseCommit(); // then verify(originalResponse).reset(); }
@Test void testPreResponseCommit4() { // setup decoraResponseWrapper = new DecoraResponseWrapper(originalRequest, originalResponse, lastModifiedData, decoraManager); when(lastModifiedData.getLastModified()).thenReturn(Long.valueOf(1)); when(originalResponse.containsHeader("Last-Modified")).thenReturn(false); when(originalRequest.getDateHeader("If-Modified-Since")).thenReturn(Long.MIN_VALUE); // when decoraResponseWrapper.preResponseCommit(); // then verify(originalResponse).setDateHeader("Last-Modified", lastModifiedData.getLastModified()); }
@Test void testPreResponseCommit2() { // setup decoraResponseWrapper = new DecoraResponseWrapper(originalRequest, originalResponse, lastModifiedData, decoraManager); when(lastModifiedData.getLastModified()).thenReturn(Long.valueOf(-1)); when(originalResponse.containsHeader("Last-Modified")).thenReturn(true); // when decoraResponseWrapper.preResponseCommit(); // then verify(originalResponse, never()).setDateHeader("Last-Modified", 1); verify(originalResponse, never()).reset(); verify(lastModifiedData).getLastModified(); }
@Test void testPreResponseCommit3() { // setup decoraResponseWrapper = new DecoraResponseWrapper(originalRequest, originalResponse, lastModifiedData, decoraManager); when(lastModifiedData.getLastModified()).thenReturn(Long.valueOf(-1)); when(originalResponse.containsHeader("Last-Modified")).thenReturn(false); // when decoraResponseWrapper.preResponseCommit(); // then verify(originalResponse, never()).setDateHeader("Last-Modified", 1); verify(originalResponse, never()).reset(); verify(lastModifiedData).getLastModified(); }
/** * Delegate OPTIONS requests to {@link #processRequest}, if desired. * <p>Applies HttpServlet's standard OPTIONS processing otherwise, * and also if there is still no 'Allow' header set after dispatching. * @see #doService */ @Override protected void doOptions(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (this.dispatchOptionsRequest || CorsUtils.isPreFlightRequest(request)) { processRequest(request, response); if (response.containsHeader("Allow")) { // Proper OPTIONS response coming from a handler - we're done. return; } } // Use response wrapper in order to always add PATCH to the allowed methods super.doOptions(request, new HttpServletResponseWrapper(response) { @Override public void setHeader(String name, String value) { if ("Allow".equals(name)) { value = (StringUtils.hasLength(value) ? value + ", " : "") + HttpMethod.PATCH.name(); } super.setHeader(name, value); } }); }
if (!response.containsHeader(HEADER_CACHE_CONTROL)) { if (getSessionAttributesHandler(handlerMethod).hasSessionAttributes()) { applyCacheSeconds(response, this.cacheSecondsForSessionAttributeHandlers);