itinance / react-native-fs

Native filesystem access for react-native
MIT License
4.89k stars 954 forks source link

Content-Length http header might be missing #1185

Open jaygooby opened 1 year ago

jaygooby commented 1 year ago

This line https://github.com/itinance/react-native-fs/blob/64aa755cc1d37f59fa205bf2d52dd71a7d691504/windows/RNFS/RNFSManager.cpp#L947 assumes that there's always a content-length header returned as part of a http request, but if the client has issued an Accept-Encoding: gzip, deflate, br header, then the content-length header will be missing from the server, because the server has entered streaming mode, returning an on-the-fly compressed response, where the content-length can't be known in advance.

The lack of the content-length causes the library to crash in these cases.

Here's a curl session where the content-length is returned:

curl 'https://placehold.co/600x400/EEE/31343C' -v -o /dev/null  2>&1 | grep -i content-length
$ < Content-Length: 6010

and here's the same request when the client says it can take a compressed response:

curl --http1.1 'https://placehold.co/600x400/EEE/31343C' -v -o /dev/null -H 'Accept-Encoding: gzip, deflate, br' 2>&1 | grep -i content-length

no content-length is present