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

Using directory's ETag/modified time when serving an index file/listing #73

Closed
rmobis opened this issue Jan 6, 2016 · 3 comments
Closed

Comments

@rmobis
Copy link

rmobis commented Jan 6, 2016

When the index option is set to any value other than false and st is actually serving some content for directory paths, it uses the directory's ETag (and consequently its modified time) for the ETag header instead of the file's.

Since a directory's modified time property is only updated when a file directly inside it is created, deleted or renamed [1], a file inside a directory could be modified without updating the directory's modified time. This is a problem because:

  • When serving a file on the index it may not serve the modified, updated file because of client caching.
  • When serving a listing of the directory the file's sizes and modified times may not be properly displayed because of client caching.

MCV

To reproduce the issue, I've had the following files:

index.js

var st = require('st'),
    http = require('http')

http.createServer(
    st({
        path: __dirname + '/test',
        index: 'index.html',
        cache: false,
    })
).listen(8080)

test/index.html

0

I started the server with node index.js, and accessed it on localhost:8080. I made changes on the test/index.html file and refreshed the page (without clearing cache), but it didn't reflect my changes.

PS: It did reflect the changes when I accessed localhost:8080/index.html.
PS²: It may reflect the changes if you have atomic saving enabled on your text editor.


Possible solutions

  • When serving a file, use its ETag value instead.
  • When serving a directory listing:
    • generate an ETag taking into consideration the ETag for all files inside it;
    • don't set the ETag header at all.

I'm not sure which solution for the directory listing is less worse and I can't really think of any other solution.

I'd be happy to work on a PR as soon as you figure what solution would be better.

  1. http://serverfault.com/a/27402/162399
    (I know this is hardly a canonical reference, but I found multiple mentions on multiple sources describing the exact same behavior. Also, it makes a lot of sense.)
@rvagg
Copy link
Collaborator

rvagg commented Nov 11, 2019

closing due to age

@rvagg rvagg closed this as completed Nov 11, 2019
@rmobis
Copy link
Author

rmobis commented Nov 11, 2019

@rvagg I guess I'd still be willing to work on a PR if you could point which of the suggested solutions (or another one) would be better suited.

@rvagg
Copy link
Collaborator

rvagg commented Nov 11, 2019

ehh, I don't have very strong opinions on this other than - I'd look at what common software does, what does nginx do?

When serving a file, use its ETag value instead.

that sounds reasonable, current behaviour as you describe it seems like a bug

When serving a directory listing:
generate an ETag taking into consideration the ETag for all files inside it;
don't set the ETag header at all.

this is where you could look around to see what others do, I'd be tempted to take the easy path of no-etag but maybe there's a better way.

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

No branches or pull requests

2 participants