Thursday, May 18, 2017

Possible solution to preflight problem with Options request in a Rest Service under Chrome.


There is a common error under rest service development with AngularJS framework after that understood that internally the framework do OPTIONS requests to know who is invoking an error like follows can occur:

Response for preflight has invalid HTTP status code 400

The possible solution to this problem is to check CORSFilter and when the request contains a OPTIONS just respond an OK status:

...
    if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
        response.setStatus(HttpServletResponse.SC_OK);
    } else {
        chain.doFilter(req, res);
    }

Important links:


No comments:

Post a Comment