|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.web.filter;
|
18 | 18 |
|
19 | 19 | import java.io.IOException;
|
| 20 | +import javax.servlet.DispatcherType; |
20 | 21 | import javax.servlet.FilterChain;
|
21 | 22 | import javax.servlet.ServletException;
|
22 | 23 | import javax.servlet.ServletRequest;
|
@@ -93,6 +94,7 @@ public final void doFilter(ServletRequest request, ServletResponse response, Fil
|
93 | 94 | HttpServletResponse httpResponse = (HttpServletResponse) response;
|
94 | 95 |
|
95 | 96 | String alreadyFilteredAttributeName = getAlreadyFilteredAttributeName();
|
| 97 | + alreadyFilteredAttributeName = updateForErrorDispatch(alreadyFilteredAttributeName, request); |
96 | 98 | boolean hasAlreadyFilteredAttribute = request.getAttribute(alreadyFilteredAttributeName) != null;
|
97 | 99 |
|
98 | 100 | if (hasAlreadyFilteredAttribute || skipDispatch(httpRequest) || shouldNotFilter(httpRequest)) {
|
@@ -165,6 +167,21 @@ protected String getAlreadyFilteredAttributeName() {
|
165 | 167 | return name + ALREADY_FILTERED_SUFFIX;
|
166 | 168 | }
|
167 | 169 |
|
| 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 | + |
168 | 185 | /**
|
169 | 186 | * Can be overridden in subclasses for custom filtering control,
|
170 | 187 | * returning {@code true} to avoid filtering of the given request.
|
|
0 commit comments