tower-rs / tower-http

HTTP specific Tower utilities.
680 stars 159 forks source link

ServeDir lacks the `Last-Modified` response header #411

Open photino opened 11 months ago

photino commented 11 months ago

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

nathaniel-daniel commented 11 months ago

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

photino commented 11 months ago

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.

nathaniel-daniel commented 11 months ago

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.