Open enspritz opened 1 month ago
That seems reasonable. The header removal can be achieved via find-header
. A private function could be added to the not-modified namespace to remove the header:
(defn- remove-header [response header]
(dissoc-in response [:headers (key (find-header response header))]))
This might be also useful generally, but better to not change the API when making a fix.
(wrap-not-modified)
setsContent-Length
is set to0
on 304 Not Modified responses. I propose that it is better practice to completely remove theContent-Length
header from those responses.We can bench-press RFCs (now-superseded RFC 2616 §10.3.5, RFC 7230 §3.3.2, RFC 7232 §4.1 ); online discussion helps to untangle the abridged nature of those documents and elucidate its practical applications. There seems to be a rough consensus that content length should be omitted, as in 0 1.
The strongest signal for me comes from 3 places, downstream of the RFCs: Popular web server implementations like Apache HTTPD and NGINX, highly-trafficked web properties like amagooface, and intermediate services and equipment implementations like firewalls and caches. My personal experience is they will either omit
Content-Length
(easiest!) or more hazardously fill in the actual number of bytes ("octets") modulo a bunch of conditions I don't want to waste precious life-span agitating for.Accord to a cursory inspection, high-traffic web properties, whose stable operations depend on getting such fine details right in the real world, uniformly omit
Content-Length
. For example:So in terms of
(wrap-not-modified)
, instead of addingContent-Length
to the response headers at line 49: https://github.com/ring-clojure/ring/blob/f92911c26e029ef8579066e0d876dbc03b18b550/ring-core/src/ring/middleware/not_modified.clj#L46-L51I propose a better course of action is to dissociate
Content-Length
from the headers. I'd submit a PR, but I didn't note any established precedent in the code base for the removal of a header based on its name (HTTP nomenclature) being either a Clojure keyword or a case-insensitive string, so I'm not sure how you'd like it done.