Skip to content

Commit 9f81484

Browse files
committed
Separate "filtered" attribute for ERROR dispatch
Closes gh-22989
1 parent 2ed81be commit 9f81484

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

spring-web/src/main/java/org/springframework/web/filter/OncePerRequestFilter.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.web.filter;
1818

1919
import java.io.IOException;
20+
import javax.servlet.DispatcherType;
2021
import javax.servlet.FilterChain;
2122
import javax.servlet.ServletException;
2223
import javax.servlet.ServletRequest;
@@ -93,6 +94,7 @@ public final void doFilter(ServletRequest request, ServletResponse response, Fil
9394
HttpServletResponse httpResponse = (HttpServletResponse) response;
9495

9596
String alreadyFilteredAttributeName = getAlreadyFilteredAttributeName();
97+
alreadyFilteredAttributeName = updateForErrorDispatch(alreadyFilteredAttributeName, request);
9698
boolean hasAlreadyFilteredAttribute = request.getAttribute(alreadyFilteredAttributeName) != null;
9799

98100
if (hasAlreadyFilteredAttribute || skipDispatch(httpRequest) || shouldNotFilter(httpRequest)) {
@@ -165,6 +167,21 @@ protected String getAlreadyFilteredAttributeName() {
165167
return name + ALREADY_FILTERED_SUFFIX;
166168
}
167169

170+
private String updateForErrorDispatch(String alreadyFilteredAttributeName, ServletRequest request) {
171+
172+
// Jetty does ERROR dispatch within sendError, so request attribute is still present
173+
// Use a separate attribute for ERROR dispatches
174+
175+
if (DispatcherType.ERROR.equals(request.getDispatcherType()) && !shouldNotFilterErrorDispatch() &&
176+
request.getAttribute(alreadyFilteredAttributeName) != null) {
177+
178+
return alreadyFilteredAttributeName + ".ERROR";
179+
}
180+
181+
182+
return alreadyFilteredAttributeName;
183+
}
184+
168185
/**
169186
* Can be overridden in subclasses for custom filtering control,
170187
* returning {@code true} to avoid filtering of the given request.

0 commit comments

Comments
 (0)