Skip to content

Commit

Permalink
Capture the ServletRequest for use in the downstream ws upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias committed Jan 23, 2015
1 parent b8ffd5d commit 79cd15e
Showing 1 changed file with 15 additions and 4 deletions.
Expand Up @@ -19,8 +19,13 @@
*
* So, this filter sends a request down the chain that doesn't have a pathInfo
* if the request is a websocket upgrade request.
*
* It also grabs the original ServletRequest in a ThreadLocal for the
* downstream handshake to use.
*/
public class PathInfoRemovingFilter implements Filter {
public class WebSocketHelpyHelpersonFilter implements Filter {

public static final ThreadLocal<HttpServletRequest> requestTL = new ThreadLocal<>();

@Override
public void init(FilterConfig filterConfig) throws ServletException {
Expand All @@ -30,8 +35,14 @@ public void init(FilterConfig filterConfig) throws ServletException {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (request instanceof HttpServletRequest &&
!(request instanceof PathInfoRemovingRequestJacket) && // this filter has already been applied
"websocket".equalsIgnoreCase(((HttpServletRequest) request).getHeader("Upgrade"))) {
chain.doFilter(new PathInfoRemovingRequestFacade((HttpServletRequest)request), response);
requestTL.set((HttpServletRequest)request);
try {
chain.doFilter(new PathInfoRemovingRequestJacket((HttpServletRequest) request), response);
} finally {
requestTL.remove();
}
} else {
chain.doFilter(request, response);
}
Expand All @@ -42,8 +53,8 @@ public void destroy() {

}

class PathInfoRemovingRequestFacade extends HttpServletRequestWrapper {
public PathInfoRemovingRequestFacade(HttpServletRequest request) {
class PathInfoRemovingRequestJacket extends HttpServletRequestWrapper {
public PathInfoRemovingRequestJacket(HttpServletRequest request) {
super(request);
}

Expand Down

0 comments on commit 79cd15e

Please sign in to comment.