Skip to content

Commit

Permalink
Fix for #366 [runtime] Prevent AtmosphereFilter to intercept static r…
Browse files Browse the repository at this point in the history
…esource
  • Loading branch information
jfarcand committed May 17, 2012
1 parent e55de4c commit 1daec90
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,8 @@ public interface ApplicationConfig {
* gets delivered to an application or framework
*/
String ATMOSPHERE_INTERCEPTORS = AtmosphereInterceptor.class.getName();
/**
* Regex pattern for excluding file from being serviced by {@link AtmosphereFilter}
*/
String ATMOSPHERE_EXCLUDED_FILE = AtmosphereFilter.class.getName() + ".excludes";
}
23 changes: 21 additions & 2 deletions modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public class AtmosphereFilter implements Filter {

private final AtmosphereServlet as;

private final static String EXCLUDE_FILES = "^.*\\.(ico|ICO|jpg|JPG|gif|GIF|doc|DOC|pdf|PDF)$";

private String excluded = EXCLUDE_FILES;

public AtmosphereFilter() {
as = new AtmosphereServlet(true);
}
Expand Down Expand Up @@ -113,6 +117,12 @@ public Enumeration<String> getInitParameterNames() {
return filterConfig.getInitParameterNames();
}
});

String s = filterConfig.getInitParameter(ApplicationConfig.ATMOSPHERE_EXCLUDED_FILE);
if (s != null) {
excluded = s;
}

}

/**
Expand All @@ -126,8 +136,17 @@ public Enumeration<String> getInitParameterNames() {
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
Action a = as.framework().doCometSupport(AtmosphereRequest.wrap((HttpServletRequest) request),
AtmosphereResponse.wrap((HttpServletResponse) response));

AtmosphereRequest req = AtmosphereRequest.wrap((HttpServletRequest) request);
AtmosphereResponse res = AtmosphereResponse.wrap((HttpServletResponse) response);
Action a = null;

if (req.getServletPath() == null
|| (as.framework().getServletContext().getResource(req.getServletPath()) == null
&& !req.getServletPath().matches(excluded) )) {
a = as.framework().doCometSupport(req,res);
}

if (a == null || a.type() != Action.TYPE.SUSPEND) {
chain.doFilter(request, response);
}
Expand Down

0 comments on commit 1daec90

Please sign in to comment.