You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.)
The text was updated successfully, but these errors were encountered:
When the
index
option is set to any value other thanfalse
andst
is actually serving some content for directory paths, it uses the directory'sETag
(and consequently its modified time) for theETag
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:
MCV
To reproduce the issue, I've had the following files:
index.js
test/index.html
I started the server with
node index.js
, and accessed it onlocalhost:8080
. I made changes on thetest/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
ETag
value instead.ETag
taking into consideration theETag
for all files inside it;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.
(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.)
The text was updated successfully, but these errors were encountered: