tower-http icon indicating copy to clipboard operation
tower-http copied to clipboard

ServeDir lacks the `Last-Modified` response header

Open photino opened this issue 9 months ago • 3 comments

Bug Report

Version

0.4.4

Platform

64-bit (Windows)

Crates

Description

The ServeDir lacks the Last-Modified response header even when it returns a 304 response.

image

photino avatar Sep 23 '23 12:09 photino

To my understanding, it isn't strictly required to send a Last-Modified header for 304 responses: https://datatracker.ietf.org/doc/html/rfc9110#section-15.4.5

nathaniel-daniel avatar Oct 10 '23 00:10 nathaniel-daniel

It is also OK to return an ETag header. Without either Last-Modified or ETag, it is difficult for us to ensure that the content is unchanged.

photino avatar Oct 10 '23 03:10 photino

It is also OK to return an ETag header. Without either Last-Modified or ETag, it is difficult for us to ensure that the content is unchanged.

Well, you would know it's unchanged because of the 304 response. An ETag header seems necessary for 304s, but a Last-Modified isn't. Also note that ServeDir doesn't use ETags at all. It is also explicitly stated that a Last-Modified header may be useful for responses without an ETag, but it isn't required.

I was just trying to note that the current behavior isn't technically wrong, but it might still be worthwhile to send a Last-Modified header for 304 responses.

nathaniel-daniel avatar Oct 10 '23 03:10 nathaniel-daniel