Hi I have simple service worker, but my Range header is not being send even thought i can log it on request object.
self.addEventListener('fetch', async function(event) {
if (event.request.headers.get("range")) {
const response = await fetch(event.request.clone());
return event.respondWith(this.getPartialResponse(event.request, response));
}
return event.respondWith(fetch(event.request));
}
async getPartialResponse(req, res) {
const pos = Number(/^bytes\=(\d+)\-$/g.exec(req.headers.get("range"))[1]);
const ab = await res.arrayBuffer();
const headers = new Headers(res.headers);
headers.append("Content-Range", `bytes ${pos}-${ab.byteLength - 1}/${ab.byteLength}`);
headers.append("Content-Length", ab.byteLength - pos + 1);
return new Response(ab.slice(pos), {
status: 206,
statusText: "Partial Content",
headers
});
}
Here you can see request one catched by service worker and the second one send to the api where you can notice the Range
header is missing. Why ? My browser: Chrome/59.0.3071.104