jamesfredley commented on code in PR #16516:
URL: https://github.com/apache/grails-core/pull/16516#discussion_r4407447292


##########
grails-web-mvc/src/main/groovy/org/grails/web/servlet/mvc/GrailsDispatcherServlet.groovy:
##########
@@ -60,18 +61,18 @@ class GrailsDispatcherServlet extends DispatcherServlet 
implements ServletContex
 
     @Override
     protected ServletRequestAttributes 
buildRequestAttributes(HttpServletRequest request, HttpServletResponse 
response, RequestAttributes previousAttributes) {
-        if (previousAttributes == null || !(previousAttributes instanceof 
GrailsWebRequest)) {
-            return buildGrailsWebRequest(request, response)
-        }
-        else {
-            GrailsWebRequest webRequest = (GrailsWebRequest) previousAttributes
-            if (webRequest.isActive()) {
-                return webRequest
-            }
-            else {
-                return buildGrailsWebRequest(request, response)
-            }
+        GrailsWebRequest webRequest = previousAttributes instanceof 
GrailsWebRequest
+                ? (GrailsWebRequest) previousAttributes
+                : GrailsWebRequest.lookup(request)
+        // A later RequestContextFilter can replace the thread binding while 
the Grails filter's
+        // request attribute still holds the active instance used by URL 
mappings.
+        if (webRequest == null || !webRequest.isActive()) {

Review Comment:
   A filter after Grails can wrap the request and response and leave a plain 
ServletRequestAttributes on the thread. lookup then finds the GrailsWebRequest 
stored on the request, which still holds the objects from before that wrapper. 
This active instance is reused, so the controller and the renderer never see 
the wrapper. A caching response wrapper does not receive the rendered bytes. 
Build the context from the servlet's current request and response, and keep the 
rendering state the earlier instance holds.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to