Created
November 16, 2016 18:05
-
-
Save joemccall86/b434aa52cdf6802f9ccc72b672976fff to your computer and use it in GitHub Desktop.
Extended class for working around #10319
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import grails.artefact.Interceptor | |
import groovy.transform.CompileStatic | |
import javax.servlet.http.HttpServletRequest | |
/** | |
* Workaround for https://github.com/grails/grails-core/issues/10319 | |
* | |
* Allows an interceptor to behave properly when server.contextPath is set | |
*/ | |
@CompileStatic | |
trait ContextPathAwareInterceptor extends Interceptor { | |
@Override | |
boolean doesMatch(HttpServletRequest request) { | |
super.doesMatch(new ContextPathRemovingRequestWrapper(originalRequest: request)) | |
} | |
/** | |
* Wrapper that intercepts the request URI and removes the context path | |
*/ | |
static class ContextPathRemovingRequestWrapper implements HttpServletRequest { | |
@Delegate HttpServletRequest originalRequest | |
@Override | |
String getRequestURI() { | |
originalRequest.requestURI - contextPath | |
} | |
} | |
} |
That doesn't seem to address the case where the server.contextPath
is set in config. The value of entryPoint
will still be checked against a string that still contains the contextPath
. Am I missing something?
No I think I was mistaken. So by subtracting the contextPath, are you trying to match on:
scheme + "://" + serverName + ((includePort) ? (":" + serverPort) : "")
??? Because the forwardUri == contextPath effectively. The above would give you a blank string (as far as I know).
What are you try for as an outcome?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Graeme doesn't like me to contribute and has blocked me so I thought I would add here...
Very easy fix if you do something like this...
... or something like that. I have had to work this into alot of what I do and this works great and provides the fastest response.
You just have to separate out as a variable first, then match it.
In this case. if my APPLICATION_VERSION was '0.1', it would match on 'api/v0.1'