martinsileno / pubg-typescript-api

TypeScript wrapper on official PUBG API.
MIT License
12 stars 9 forks source link

Error in Chrome - Refused to set unsafe header "Accept-Encoding" #6

Closed Otrozone closed 6 years ago

Otrozone commented 6 years ago

In Chrome browser I'm getting Refused to set unsafe header "Accept-Encoding" error message every time when a request is processed. According to this StackOverflow question, the Accept-Encoding should not be part of the header. But I'm not sure, what it exactly does and what it can affects. Anyway if I remove the Accept-Encoding in constructor of PubgAPI class in pubg-typescript-api\api\base.js, it works fine and the error is not produced:

        /*if (useGzip) {
            headers['Accept-Encoding'] = 'gzip';
        }*/

Btw. great job, I like this wrapper.

martinsileno commented 6 years ago

Hi, thanks for reporting.

I added the header to make the server respond with gzipped content, as explained here.

However, it appears that this is a forbidden header name for browsers, but it is fine when sending requests from other sources (like node).

Just to confirm, do you get a gzipped response (does the server reply with Content-Encoding: gzip) after commenting out the Accept-Encoding header?

I will patch it by defaulting useGzip to false, so that it can be set to true when initializing PubgAPI when using node and it stays false if sending requests through a browser.

Otrozone commented 6 years ago

Hello, I used the wrapper in fully client side application, so it was used quite unusual way. Expected usage is here server to server, where the Accept-Encoding could be smooth. So my error report was probably misleading. Sorry for that.

The new version #7 (1.3.1) works perfectly w/o error even on client side. It looks like the response is using gzip. Here are the headers for new version:

General
Request URL: https://api.playbattlegrounds.com/shards/pc-eu/matches/41dd024d-9bc5-4b76-b0d8-6c0330d675d3
Request Method: GET
Status Code: 200  (from disk cache)
Remote Address: 54.230.129.45:443
Referrer Policy: no-referrer-when-downgrade

Response headers
access-control-allow-origin: *
access-control-expose-headers: Content-Length
age: 42254
cache-control: max-age=604800
content-encoding: gzip
content-type: application/json
date: Tue, 22 May 2018 19:01:18 GMT
status: 200
vary: Accept-Encoding
via: 1.1 e50082f108f86da8af6ed222cfcad2b5.cloudfront.net (CloudFront)
x-amz-cf-id: CYsmtNcLlE_sHx48lV8jmWPYZwN1n6qWdfeafX_ZcYm4BETcs6nMyA==
x-cache: Hit from cloudfront
x-request-id: 604b0c16-01e3-4638-9357-770e93891270

Request headers
Provisional headers are shown
Accept: application/json
Authorization: Bearer eyJ...KmWKWaM
Origin: http://localhost:4200
Referer: http://localhost:4200/matches
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36

Thank you.