Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CORS mocking #21

Open
klr8 opened this issue Oct 2, 2018 · 0 comments
Open

Allow CORS mocking #21

klr8 opened this issue Oct 2, 2018 · 0 comments

Comments

@klr8
Copy link

klr8 commented Oct 2, 2018

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;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants