cloudhead / node-static

rfc 2616 compliant HTTP static-file server module, with built-in caching.
MIT License
2.17k stars 245 forks source link

Invalid or unsupported Range Request Header #209

Closed vovchisko closed 3 years ago

vovchisko commented 6 years ago

In my server logs I've got a lots of such errors:

Request contains unsupported range header:  bytes: 0-22
Error: Range request present but invalid, might serve whole file instead
    at Server.respondNoGzip (/home/ed-void/node_modules/node-static/lib/node-static.js:297:23)
    at Server.respond (/home/ed-void/node_modules/node-static/lib/node-static.js:350:14)
    at /home/ed-void/node_modules/node-static/lib/node-static.js:93:14
    at FSReqWrap.oncomplete (fs.js:171:5)
Range request exceeds file boundaries, goes until byte no 2097152 against file size of 8409 bytes
Error: Range request present but invalid, might serve whole file instead
    at Server.respondNoGzip (/home/ed-void/node_modules/node-static/lib/node-static.js:297:23)
    at Server.respond (/home/ed-void/node_modules/node-static/lib/node-static.js:350:14)
    at /home/ed-void/node_modules/node-static/lib/node-static.js:93:14
    at FSReqWrap.oncomplete (fs.js:171:5)

I think this one was made by the same client:

Range request exceeds file boundaries, goes until byte no 2097152 against file size of 9031 bytes
Error: Range request present but invalid, might serve whole file instead
    at Server.respondNoGzip (/home/ed-void/node_modules/node-static/lib/node-static.js:297:23)
    at Server.respond (/home/ed-void/node_modules/node-static/lib/node-static.js:350:14)
    at /home/ed-void/node_modules/node-static/lib/node-static.js:93:14
    at FSReqWrap.oncomplete (fs.js:171:5)

My guess is most of cleint browsers is mobile. As node-static serve whole file in such situation anyway - can I mute this errors somehow?

tchakabam commented 6 years ago

You should probably rather check why the client is doing this wrong instead of muting the error.

node-static doesn't support this range-header, it should look like: bytes=0-22.

This range you see in the error message isn't standard.

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests

Also note that static only implements single-part ranges :)

If you really want to mute the error, change this line: https://github.com/cloudhead/node-static/blob/master/lib/node-static.js#L297

vovchisko commented 6 years ago

@tchakabam I agree. But I can't do anything about it. This range requested by SeaMonkey or/and mobile FF. I don't know for sure. I think ns can emit error event (or any other error), not just throw it. And if no listener for error event - thne okay, throw it. :3

tchakabam commented 6 years ago

I think ns can emit error event (or any other error), not just throw it.

It doesn't throw an error, it just uses console.error to log it