Use of Content-Type (vs Accept) header for setting XHR responseType to 'arraybuffer'
When fetching, we have this block to configure the outbound XHR:
if ('responseType' in xhr) {
if (support.blob) {
xhr.responseType = 'blob'
} else if (
support.arrayBuffer &&
request.headers.get('Content-Type') &&
request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1
) {
xhr.responseType = 'arraybuffer'
}
}
I'm curious why the request's Content-Type is used as a heuristic for requesting an ArrayBuffer. For a GET request, we often won't have a Content-Type at all because there's no body in the request.
Should this instead be the Accept header, indicating the type of content that the sender is expecting to receive from the server?
My team is running into an issue where in order to get the desired behavior from the polyfill we need to add a Content-Type header to our requests which is a bit unnatural - it seems like Accept is a cleaner HTTP fit here.
This issue is exposed on React Native clients where ArrayBuffer works as expected (so we want an ArrayBuffer out of the XHR), but Blob does not, so support.blob is false.
When fetching, we have this block to configure the outbound XHR:
if ('responseType' in xhr) { if (support.blob) { xhr.responseType = 'blob' } else if ( support.arrayBuffer && request.headers.get('Content-Type') && request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1 ) { xhr.responseType = 'arraybuffer' } }I'm curious why the request's
Content-Typeis used as a heuristic for requesting an ArrayBuffer. For a GET request, we often won't have aContent-Typeat all because there's no body in the request.Should this instead be the Accept header, indicating the type of content that the sender is expecting to receive from the server?
My team is running into an issue where in order to get the desired behavior from the polyfill we need to add a
Content-Typeheader to our requests which is a bit unnatural - it seems likeAcceptis a cleaner HTTP fit here.This issue is exposed on React Native clients where ArrayBuffer works as expected (so we want an ArrayBuffer out of the XHR), but Blob does not, so
support.blobis false.
https://github.com/github/fetch/issues/997#issue-950012817