citrus-simulator
citrus-simulator copied to clipboard
Allow CORS mocking
It would be nice if the REST simulator had support for mocking / doing CORS. It's easy enough to do it now by registering a HandlerInterceptor, but it would be nice if this kind of thing could be provided out-of-the-box:
public class CorsHandlerInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (CorsUtils.isCorsRequest(request)) {
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "*");
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "*");
if (CorsUtils.isPreFlightRequest(request)) {
return false;
}
}
return true;
}
}