citrus-simulator icon indicating copy to clipboard operation
citrus-simulator copied to clipboard

Allow CORS mocking

Open klr8 opened this issue 7 years ago • 0 comments

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;
  }
}

klr8 avatar Oct 02 '18 12:10 klr8