-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add range request and etag support to file_server.ts
#1028
Conversation
- Basic etag support - Server name header - Date and Last-Modified headers - Added ~200 additional mimetypes
Personal opinion is that this is really getting into the range of what a Web server framework does. file_server is intended to be a minimalist example application. Also it doesn't have tests, but even with exhaustive tests I would feel the same way, that it isn't part of the std library. |
Agreed on the tests. I'm working on them. I wanted to get some feedback on this first. Is I'm not sure how supporting a basic HTTP 1.1 feature makes it a 'framework'? Without range support, it is basically an HTTP 1.0 server. I know I have a video player app that I work on that does thumbnailing for any video URL. Lack of range support caused it to either: 1) only ever show the very first frame no matter the requested timestamp, or 2) it wouldn't work at all, but also wasn't throwing a visible error in the browser. The issue affected playback too. The browser video engine wouldn't seek (even fully downloaded files) or would have to download the entire file because the MP4 index was at the end. |
- Set standard base headers (`server`, `accept-ranges`, `date`) for all responses - Fixed handling of malformed range requests - `response.body` is empty for 304 responses
- Added tests for: range requests, etag headers, mime-type headers, date headers - Populated test `hello.html` and `test file.txt` files with test data
…e test, contentType test - CORS has its own specific test now - Excess tests for CORS removed from other tests - Corrected test for `/testdata/%` URL - Fixed contentType test - All tests now pass
I have added and fixed all the tests in |
Of course all of the tests passed on my machine, but not on the CI. The file metadata (length, date) is being returned different, probably due to platform differences. I'm changing them to dynamically pull the metadata instead of it being hard coded. |
I'm slightly in favor of including this change because according to the file's history we've been accepting the PRs which simply add the usability as a file server, (which therefore reduce the minimality as an example). I think this is one of that types of changes. But I'd like to hear other collaborators opinions as well. |
Fixed a couple of hardcoded values I missed in 2 tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This falls in the scope of the file_server.ts and looks well-implemented with tests. Thank you for this PR @pseudosavant !
I'm a little concerned that the file_server now depends on createHash. Can crypto.subtle.digest be used instead?
Sure, that was a straight-forward change. I just pushed a commit for it. |
file_server.ts
file_server.ts
"", | ||
); | ||
return hashHex; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is duplicated... Seems better if you export it.
Also the .join("",)
seems odd...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can move that out into a module. Is there guidance on where I should put that in the repo?
As for the join
. Agreed .join("",)
looks odd. But do you mean the trailing comma or joining the array into strings using join
? The comma and line break are being added by deno fmt
. I don't understand why it is doing that though. That method only accepts 1 argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a commit to make createEtagHash
clearer, and format better. It doesn't address moving it out into a module yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ry Any guidance on where I should put the module? Should I put it in something like _createEtagHash.ts
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would work. But I question whether the test needs the ability to create the etag header generally - how about just hardcoding some expected etag values into the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first tests did used hard coded values but it didn't work. I learned that the last modified time, and the system reported file size, aren't consistent across environments. Those are the two inputs, concatenated, for createEtagHash
.
LGTM except CLA check error. It seems 2 email addresses are used in the commits and one of them causing the error... @pseudosavant Can you fix this situation? |
I've been trying to get it corrected. I didn't realize my git config was slightly different on one of my other machines I used. I followed the CLA assistant's directions and added and verified the other email address in my GitHub account. The CLA assistant doesn't seem to pick it up though. And when I try doing the assistant again it says I've signed it already. Do you know of another way I could fix this? |
Only the last commit had a different email address. I squashed it to the one before it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pseudosavant Thank you for your contribution!
Thanks for the help getting it merged in! Deno is a great project. 🙏 |
First pass at adding support for range requests