Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GrailsWebRequestFilter doesn't clearGrailsWebRequest when isIncludeOrForward && previous == null #13593

Open
felixscheinost opened this issue Aug 28, 2024 · 0 comments

Comments

@felixscheinost
Copy link

felixscheinost commented Aug 28, 2024

Expected Behavior

We are calling a Grails servlet from another servlet to handle some URLs in a backwards compatible way.

So basically we have:

object : HttpServlet() {
  override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
    val dispatcher = grailsContext.servletContext.getRequestDispatcher(<some logic>)
    // Forward to some other path in Grails
    dispatcher.forward(req, resp)
  }
}

I agree this is probably a very uncommon usecase but for us it is the only way.

After dispatcher.forward(...) the RequestContextHolder should always be empty again, right?

Actual Behaviour

Actually, GrailsWebRequestFilter incorrectly doesn't reset RequetContextHolder if the request is an include or forward.

Why? I don't think there really is a reason, it is just a else that was never written.

The code currently is:

if(isIncludeOrForward) {
    if(previous != null) {
        WebUtils.storeGrailsWebRequest(previous);
    }
}
else {

    WebUtils.clearGrailsWebRequest();
    LocaleContextHolder.setLocale(null);
}

I think it should be:

  if (previous != null) {
     WebUtils.storeGrailsWebRequest(previous);
  } else {
      WebUtils.clearGrailsWebRequest();
 }

Reason: We must ALWAYS reset the world to how we found it before. So either reset the previous or clear it.

Steps To Reproduce

No response

Environment Information

No response

Example Application

No response

Version

Latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant