Reputation: 103
I have a React app which is fetching data from a server this way:
fetch('http://localhost:5000/records',{
method:'GET',
headers:{
'ACCEPT':'application/json',
'Content-Type':'application/json'
}
})
.then(response => response.json())
.then(data => {
this.setState({
records: data,
});
});
}
Inspecting network activity (dev tools Chrome/Firefox), I see:
I can add "Accept-Encoding" to my request header and give it any value or I can remove it from the header altogether. No matter what I do, inspecting the network activity always shows my request header accepting gzip, deflate and br. Is this normal? Is there a way for fetch to tell the server it doesn't want any response encoding?
I tried giving gzip a qvalue of 0 as described here, but I still see the same result in the network tab.
headers:{
'ACCEPT':'application/json',
'Content-Type':'application/json',
'Accept-Encoding': 'gzip; q=0'
}
Upvotes: 1
Views: 5355
Reputation: 944042
Accept-Encoding is a Forbidden Header. There is no way for JavaScript to change it.
Since the author of a webpage can’t know what encodings a browser is capable of decoding, it isn’t generally useful to set it anyway.
Upvotes: 4