Comments (6)
I'm sorry, but strong ETags do not fit in the model of this library. A strong ETag must guarantee octet-by-octet identicalness (especially since we support Range requests). We are also stateless (helps keep memory down, especially when used in cluster
) and streamy. To do strong ETags, you would have to hash the file contents, which means reading the whole file twice for every request: 1 to calculate the hash in a streamy fashion, 2 to send the new contents when the Etags do not match.
:(
from send.
Oh, and I forgot to say the reason we have to read the file twice is because we have to know the ETag before we know if were going to send the file, thanks to conditional requests (which are the whole point of ETags). We cannot just buffer the contents, ether, because then the server would fall over trying to serve large files (like videos).
from send.
I agree with all this! Good call.
from send.
What if you never modify the file during the server lifetime? If we make that assumption, could we perhaps calculate a strong ETag for all the files of the directory on startup?
from send.
Hi @marco2216 you certainly can do that! Then you can add a headers
event listener on your send
and look up that pre-calculated ETag and set it as the ETag header and send
will use that instead of calculating one. You can then either leave etag: true
if you want fallback for when you didn't set the ETag header, or etag: false
for no fallback.
from send.
Oh right, that's pretty much what I'm doing with serve-static. I was thinking if it should be a built in option in that library - I spent a good amount of time debugging why our static files changed ETag in-between deploys even though the file was identical. But that may also just be because of my inexperience with nginx etc., I read some of your answers in other threads that it's consistent with those servers to return a value based on the file-created-time and file length.
Or maybe, if you think that's outside the scope of serve-static, it might make sense to add a line to the readme explaining what the etag is based upon by default - I wouldn't mind doing that.
from send.
Related Issues (20)
- RangeNotSatisfiableError: Range Not Satisfiable HOT 10
- Adhere to the full Streams API HOT 4
- Allow using alternate sources of files HOT 11
- Wrong behavior when handling discontinuous ranges. HOT 3
- Filenames with periods/dots using extensions option HOT 2
- Update to newer mime package to support wasm HOT 1
- progress event HOT 13
- strong etag support? HOT 4
- Can we increase the Max maxAge to 20 years? and have chance to add Expires header based on Last-modified? HOT 1
- Symlink Files HOT 4
- Allow falling back to file when directory exists but doesn't have index
- control size of partial content (206) HOT 5
- Node 15 / req.headers not defined HOT 11
- lookup not a function HOT 1
- Keep CSP on 304 HOT 6
- Unable to read /proc/* files HOT 2
- Any plan bump debug package to 3.1.0 for CVE-2017-20165? HOT 2
- Packages error - 'process is not defined' HOT 7
- Would it be possible to upgrade mime version? HOT 2
- Should 1.0.0 be `latest` on npm? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from send.