cloudhead / node-static

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

handle 206 status #242

Closed zkrige closed 1 year ago

zkrige commented 1 year ago

resolves #241

zkrige commented 1 year ago

I'm not sure about this. The latest npm repository has code from 0.7.9 in it, but it lists the version as 0.7.11

brettz9 commented 1 year ago

Thanks for the fix, but this PR has way too many changes.

  1. The diffs should be against the current version in master, not against the version in npm. There have been many changes since the npm version (whether or not @cloudhead will find the time to publish is another issue) so that is why you are seeing a different codebase.

  2. There should be no changes to whitespace, etc. unless called for by our ESLint rules. Just the changes relevant for the fix and any tests.

Thanks!

EdricCantu commented 1 year ago

@zkrige, A lot of the code has changed in this pull, and that alone makes it harder to track the significant change.

If i may ask, is the only significant change the added && status !== 206condition in Server.prototype.finish?

If so, you can just narrow down the change to that line only, unless there's something I'm missing, which I most definitely am. I'm having a hard time understanding the code, unchanged as it is, and forever I will question the usage and function of Response.writeHead.

zkrige commented 1 year ago

@EdricCantu apologies for the noise. I'll reject this PR and create a new one.

The reason for the && status !== 206 condition is as follows:

when there is a byte range, the server returns a 206 code, but it writes out the headers BEFORE this block is reached. Writing out the headers again in this block causes this exception

throw new ERR_HTTP_HEADERS_SENT('write');