A
A
Arthur2019-10-15 09:35:38
JavaScript
Arthur, 2019-10-15 09:35:38

How can I specify the encoding when responding with a ServiceWorker?

Greetings.
I connected the ServiceWorker to the site, everything works, but when caching redirects, the redirect URl comes in the wrong encoding (ISO-8859-1), although utf-8 is specified in the nginx configs, the sw.js file is encoded in utf-8, in the HTML meta code charset=utf-8 tag. When requested via CURL, the correct URL for the redirect is received, and when sw.js is disabled, everything is OK, the problem is only with the ServiceWorker.
Request from service worker:

Request URL: https://glosum.ru/?q=%D1%85%D0%B0%D0%B9%D0%BF&x=0&y=0
Request Method: GET
Status Code: 302  (from ServiceWorker)
Referrer Policy: no-referrer-when-downgrade

Server response:
content-type: text/html; charset=utf-8
date: Tue, 15 Oct 2019 06:28:29 GMT
location: /ÐоиÑк-Ñлова-Хайп
server: nginx
status: 302

But if you do a curl:
curl -v https://glosum.ru/?q=%D1%85%D0%B0%D0%B9%D0%BF&x=0&y=0

Answer:
> GET /?q=%D1%85%D0%B0%D0%B9%D0%BF HTTP/2
> Host: glosum.ru
> User-Agent: curl/7.64.0
> Accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 302
< server: nginx
< date: Tue, 15 Oct 2019 06:30:30 GMT
< content-type: text/html; charset=utf-8
< location: /Поиск-слова-Хайп

Actually, please tell me where this encoding comes from and how to defeat it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question