/** * Get the message to write to the log before the request. * @see #createMessage */ private String getBeforeMessage(HttpServletRequest request) { return createMessage(request, this.beforeMessagePrefix, this.beforeMessageSuffix); }
/** * Forms a temporary chain from the list of delegate filters supplied ({@link #setFilters}) * and executes them in order. Each filter delegates to the next one in the list, achieving * the normal behavior of a {@link FilterChain}, despite the fact that this is a {@link Filter}. * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { new VirtualFilterChain(chain, this.filters).doFilter(request, response); }
/** * Calls the {@code initFilterBean()} method that might * contain custom initialization of a subclass. * <p>Only relevant in case of initialization as bean, where the * standard {@code init(FilterConfig)} method won't be called. * @see #initFilterBean() * @see #init(javax.servlet.FilterConfig) */ @Override public void afterPropertiesSet() throws ServletException { initFilterBean(); }
@Override protected Filter[] getServletFilters() { return new Filter[] { new HiddenHttpMethodFilter(), new DelegatingFilterProxy("a"), new DelegatingFilterProxy("b"), new DelegatingFilterProxy("c") }; }
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { HttpServletResponse responseToUse = response; if (!isAsyncDispatch(request) && !(response instanceof ContentCachingResponseWrapper)) { responseToUse = new HttpStreamingAwareContentCachingResponseWrapper(response, request); } filterChain.doFilter(request, responseToUse); if (!isAsyncStarted(request) && !isContentCachingDisabled(request)) { updateResponse(request, responseToUse); } }
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (this.removeOnly) { ForwardedHeaderRemovingRequest wrappedRequest = new ForwardedHeaderRemovingRequest(request); filterChain.doFilter(wrappedRequest, response); } else { HttpServletRequest wrappedRequest = new ForwardedHeaderExtractingRequest(request, this.pathHelper); HttpServletResponse wrappedResponse = this.relativeRedirects ? RelativeRedirectResponseWrapper.wrapIfNecessary(response, HttpStatus.SEE_OTHER) : new ForwardedHeaderExtractingResponse(response, wrappedRequest); filterChain.doFilter(wrappedRequest, wrappedResponse); } }
private void disableShallowEtagHeaderFilter(ServerHttpRequest request) { if (request instanceof ServletServerHttpRequest) { ServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest(); ShallowEtagHeaderFilter.disableContentCaching(servletRequest); } }
@Override protected void doFilterInternal( HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { MultiValueMap<String, String> params = parseIfNecessary(request); if (!CollectionUtils.isEmpty(params)) { filterChain.doFilter(new FormContentRequestWrapper(request, params), response); } else { filterChain.doFilter(request, response); } }
@Override public void destroy() { Filter delegateToUse = this.delegate; if (delegateToUse != null) { destroyDelegate(delegateToUse); } }
/** * Destroy the Filter delegate. * Default implementation simply calls {@code Filter.destroy} on it. * @param delegate the Filter delegate (never {@code null}) * @see #isTargetFilterLifecycle() * @see javax.servlet.Filter#destroy() */ protected void destroyDelegate(Filter delegate) { if (isTargetFilterLifecycle()) { delegate.destroy(); } }
@Override public StringBuffer getRequestURL() { return this.forwardedPrefixExtractor.getRequestUrl(); } }
public ForwardedHeaderRemovingRequest(HttpServletRequest request) { super(request); this.headers = initHeaders(request); }
@Override public String getContextPath() { return this.forwardedPrefixExtractor.getContextPath(); }
@Override public String getRequestURI() { return this.forwardedPrefixExtractor.getRequestUri(); }
/** * Return the {@link Environment} associated with this filter. * <p>If none specified, a default environment will be initialized via * {@link #createEnvironment()}. * @since 4.3.9 */ @Override public Environment getEnvironment() { if (this.environment == null) { this.environment = createEnvironment(); } return this.environment; }
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { response = RelativeRedirectResponseWrapper.wrapIfNecessary(response, this.redirectStatus); filterChain.doFilter(request, response); }
@Test public void sendRedirectWhenRequestOnlyAndNoXForwardedThenUsesRelativeRedirects() throws Exception { this.filter.setRelativeRedirects(true); String location = sendRedirect("/a"); assertEquals("/a", location); }
@Test public void filterWithParameter() throws IOException, ServletException { filterWithParameterForMethod("delete", "DELETE"); filterWithParameterForMethod("put", "PUT"); filterWithParameterForMethod("patch", "PATCH"); }
/** * Get the message to write to the log after the request. * @see #createMessage */ private String getAfterMessage(HttpServletRequest request) { return createMessage(request, this.afterMessagePrefix, this.afterMessageSuffix); }
@Test public void filterWithParameterDisallowedMethods() throws IOException, ServletException { filterWithParameterForMethod("trace", "POST"); filterWithParameterForMethod("head", "POST"); filterWithParameterForMethod("options", "POST"); }