Created
June 3, 2013 21:34
-
-
Save Zenithar/5701628 to your computer and use it in GitHub Desktop.
This file contains 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
package org.atmosphere.interceptors; | |
import org.atmosphere.cpr.*; | |
public class CORSAtmosphereInterceptor implements AtmosphereInterceptor { | |
@Override | |
public void configure(AtmosphereConfig config) { | |
} | |
@Override | |
public Action inspect(AtmosphereResource r) { | |
AtmosphereRequest req = r.getRequest(); | |
AtmosphereResponse res = r.getResponse(); | |
if(req.getHeader("Origin") != null){ | |
res.addHeader("Access-Control-Allow-Origin", "*"); | |
res.addHeader("Access-Control-Expose-Headers", "X-Cache-Date, X-Atmosphere-tracking-id"); | |
} | |
if("OPTIONS".equals(req.getMethod())){ | |
res.addHeader("Access-Control-Allow-Methods", "OPTIONS, GET, POST"); | |
res.addHeader("Access-Control-Allow-Headers", "Origin, Content-Type, X-Atmosphere-Framework, X-Cache-Date, X-Atmosphere-tracking-id, X-Atmosphere-Transport"); | |
res.addHeader("Access-Control-Max-Age", "-1"); | |
} | |
return Action.CONTINUE; | |
} | |
@Override | |
public void postInspect(AtmosphereResource r) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Atmosphere CORS Enabler Interceptor