Skip to content
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

set real "Last-Modified" header based on file's LastWrite time #5

Merged
merged 3 commits into from
Jan 28, 2024

Conversation

vortigont
Copy link
Collaborator

Get file's LastWrite timestamp for file handlers (if supported by FS driver) and construct proper "Last-Modified" header. Works fine for LittleFS. If not supported by FS than fallback to previous implementation with manual value for "Last-Modified".

an example code to serve static files from LittleFS with IMS revalidation

// serve all static files from LittleFS root /
server.serveStatic("/", LittleFS, "/")
        .setDefaultFile("index.html")
        .setCacheControl("must-revalidate");  // revalidate based on etag/IMS headers

Get file's LastWrite timestamp for file handlers (if supported by FS driver)
and construct proper "Last-Modified" header. Works fine for LittleFS.
If not supported by FS than fallback to previous implementation with manual value for "Last-Modified".

an example code to serve static files from LittleFS with IMS revalidation
```
// serve all static files from LittleFS root /
server.serveStatic("/", LittleFS, "/")
        .setDefaultFile("index.html")
        .setCacheControl("must-revalidate");  // revalidate based on etag/IMS headers
```

Signed-off-by: Emil Muratov <[email protected]>
src/WebHandlerImpl.h Outdated Show resolved Hide resolved
src/WebHandlers.cpp Outdated Show resolved Hide resolved
Copy link
Owner

@mathieucarbou mathieucarbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some little change to confirm / update

@mathieucarbou
Copy link
Owner

@vortigont : you are currently using this mod in your app ? Can you confirm it is tested and works fine ?

@vortigont
Copy link
Collaborator Author

@vortigont : you are currently using this mod in your app ? Can you confirm it is tested and works fine ?

yes, I'm using this feature for quite a long time, works perfectly.
I update some json's on fs and browser picks it immediately after change, otherwise sever emits "not modified" reply and does not send file body

Copy link
Owner

@mathieucarbou mathieucarbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the PR locally more in depth. Here are some more comments.
No need to change the header file and you can simplify the changes in the impl.

Once the changes are done and pr rebased, good to go for me.

Thanks 👍

src/WebHandlerImpl.h Outdated Show resolved Hide resolved
src/WebHandlerImpl.h Outdated Show resolved Hide resolved
src/WebHandlers.cpp Outdated Show resolved Hide resolved
src/WebHandlers.cpp Outdated Show resolved Hide resolved
@vortigont
Copy link
Collaborator Author

OK, I've rolled back code to C style and kept as much old code as possible.

src/WebHandlers.cpp Outdated Show resolved Hide resolved
@mathieucarbou mathieucarbou added this to the 2.6.0 milestone Jan 28, 2024
@mathieucarbou mathieucarbou merged commit 84f4572 into mathieucarbou:main Jan 28, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants