Skip to content Skip to sidebar Skip to footer

Request Headers Not Sent From Service Worker

I'm trying to fetch a web service from a Service Worker. This service is a JSP secured with basic Apache authentication, so I must provide the credentials to authenticate in the re

Solution 1:

You should set as allowed headers also accept and authorization

response.setHeader(
  "Access-Control-Allow-Headers", 
  "x-requested-with, accept, authorization"
);

also body of the response for "OPTIONS" request should be empty (it is not necessary indeed, but there is no use case for body in such response) and Content-length: should be 0 (zero)

Please note, that this request should not be passed to application (you can, but not need)

Solution 2:

Pass {"credentials": "include"} as the param to the fetch() call.

https://fetch.spec.whatwg.org/

Post a Comment for "Request Headers Not Sent From Service Worker"