title: How to specify response headers to CORS?
body: <p>I am building a backend REST API in spring and my friend is building a Angular JS front end app to call my API.I have a token header with key <code>Authorization</code> and a value which gives access to the service otherwise it refuses.From Postman and REST client I am able to receive the API but when tested he says he gets 401 Unauthorized Error on preflight.Below is my doFilterInternal method.</p>
  
  <pre><code>protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
          response.setHeader("Access-Control-Allow-Origin", "*");
          response.setHeader("Access-Control-Allow-Credentials", "true");
          response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
          response.setHeader("Access-Control-Max-Age", "3600");
          response.setHeader("Access-Control-Allow-Headers","Content-Type, Accept, X-Requested-With, Authorization");
  }
  </code></pre>
  
  <p>But when he calls the API with the token in Angular JS he gets </p>
  
  <p>So I followed this answer <a href="https://stackoverflow.com/questions/42221602/response-for-preflight-has-invalid-http-status-code-401-angular">here</a> and I added the property </p>
  
  <p><code>spring.mvc.dispatch-options-request=true</code></p>
  
  <p>in the application.properties.But stillt he error seems to be like </p>
  
  <p><strong>Response for preflight has invalid https status code 401</strong></p>
  
  <p>Any help is appreciated.</p>