-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Improvements to the existing ETag implementation #8227
Conversation
Some doku: about ETagsETags are "hints" delivered with a web response in the ETag Header to the client. In the cases when the same clients will request for the same resources the server-side checksum check is a lot more effective than transferring the bytes over the network. enabling ETag supportTo enable this in the embedded web server the In the simplest version just call enableETag(true) to enable the internal ETag generation that calcs the hint using a md5 checksum in base64 encoded form. This is an simple approach that adds some time for calculation on every request but avoids network traffic. enabling ETag support customizationThe (not yet tested code):
I use the function in my project with a counter as a dummy ETag that gets incremented whenever a file changes. This depends on upload and delete functionality of the web server - so this is more complex than just to explain here in text. |
A verbose example is always nice to help understand / quickly test.
It was always enabled and will be disable by default. This is a breaking change. Did you do that for coherency with CORS ? |
Using ETAG or not depends of the use-case you implement. The implementation works in my project https://homeding.github.io/ so it's finished but an example I think will help. |
The real question is: can it be always enabled without side effects with or without clients using ETag ?
About the example, I think it will be nice to have one (there's none using |
Thanks a lot for the example ! Maybe too late, for style, there is a script |
:) I am using clang-format as I use vscode. Indent of class access modifiers is not supported there (properly) |
It's final, Can be merged. |
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.
Look goods !
Thanks for the extensive comments in the example
Dear commiters, |
True. Looking for at least one example, here's the common config from apache: Which includes both 'lightweight' content-length + modification-time (which should be available via through fs api, if one wants to implement something like it) and a more 'heavyweight' digest over the file contents. Plus, some more related to file info But
I also wonder if it's better to inject something simler as the default, and provide an example implementing the 'digest' with various hash functions and inject them with |
Do we have something simpler/faster than calculating MD5 ? Is it that slow ? I suggest to merge this PR as is (reason: let's move forward!), and someone can update defaults, examples, benchmark with subsequent PRs. |
^
Also true. |
The enableETag function has an optional parameter to pass a function. MD5 is only the (slow) default . server->enableETag(true, [this](FS &, const String &path) -> String {
String eTag;
File f = fs.open(path, "r");
eTag = f.getLastWrite()
f.close();
return (eTag);
}); |
* WebServer eTag implementation improvements
Some improvements to the existing ETag implementation.