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
Povide a setting to control req.fresh evaluation #4753
Comments
Hi @gh-andre sorry you are having trouble. We can certainly consider adding a setting to control yhe freshness support. There are various ways to disable it today, of course, just not though a setting. As for the documentation, the res.send docs do currently state that res.send does "HTTP cache freshness support". If you do not feel like that is jot adequate or have any other feedback, please open an issue or pull request against the website repository so the documentation team can addrss it. |
As for your last-modified date, you may want to take a lool at https://datatracker.ietf.org/doc/html/rfc7232#section-2.2.1 , namely the following statement which seems to be where your problem lies according to your example:
|
As for the default behavior, I understand your fustration, but SHOULD has aa specific meaning in RFCs:
It means that not following something that is a SHOULD is an exception that needs to be weighed carefully. By default, Express is following the proper procol, but performing things that are SHOULD by default. But as you stated, we can certainly add a setting to disable this, so users of the framework who carefully concider they they want to deviate from the standard behavior can do so as they like. You can currently do this in Express today, but just not though a single setting; you can override the fresh behavior with your own (for example just always return stale). As far as I know, this is the first time a request to disable this functionality has ever been requested, so it is not surprising that it has not been added yet. |
It might be difficult to figure out which of those multiple changed parts are significant and which are not. For example, item description excerpts may not contain visible changes from updates in the list, so their last updated date isn't relevant, but to figure it out is quite a technical challenge. Sending back the Anyway, thank you for looking into this. Much appreciated. I will leave it in your hands, whichever way you decide to go. Hopefully this post will provide enough description for somebody who may come across of the same issue. |
Sorry, there's some overlap in my response. I didn't notice your last edit. |
Hm, interesting. Can you link to where that definition of SHOULD is written? The one I quoted (link is https://datatracker.ietf.org/doc/html/rfc2119) seems to indicate otherwise. You seem to me to be describing the MAY keyword, is that right?
I can certainly appreciate that and we can definately disable it. But note that both intermediate proxies and even the web browsers themselves will still evaluate the last-modified header and they can decide to never even make the request to the origin server (Express) at all. In those cases, even though you disabled the check in Express, your clients will still see the outdated response. |
This comment has been minimized.
This comment has been minimized.
It's in the excerpt you mentioned - I read it as if SHOULD and RECOMMENDED describe best practices that should be followed for most cases. As long as it's understood and documented, I read it as it may be used. I do try to follow SHOULD whenever possible, but in the case I described it's quite challenging. As for browsers sending the request, they are supposed to send a conditional request whenever For Having said that, Thanks again for your insights. Very helpful. |
I think you are mostly understanding it, but if your source is the same quote, you can see that SHOULD means that any implementer (like Express) needs to follow it by default. To deviate from SHOULD "the full implications must be understood and carefully weighed before choosing a different course.". I'm confused on why you would expect a SHOULD to not be the default behavior. Can you ellaborate on what, specifically, I am missing from the RFC quote?
I'm not really following here. Can you explain a different way or perhaps, can you link to where you are looking in https://datatracker.ietf.org/doc/html/rfc7234 ? |
I'm honestly surprised that I need to elaborate on the difference between
Perhaps it's time to just close this issue. Thanks for giving it a consideration. |
It is possible to disable the behind-the-scenes logic around the
Etag
header viaapp.set("etag", false)
, but the same cannot be done against its counterpart,If-Modified-Since
and Express silently discards a fully rendered response based on just evaluatingLast-Modified
vs.If-Modified-Since
. RFC 7232 says that the304
response SHOULD be sent in this case, but doesn't say it MUST be sent, which means that some configuration, similar toetag
is needed to control this behavior.In practical terms, I may have a listing of items and
Last-Modified
in this list would be the time stamp of the last item. Some of the items may be edited, which doesn't change the last modified date of the whole list, but may benefit from intermediate items displayed in their most up-to-date form. This is just an example, though, thereq.fresh
logic shouldn't enforce this behavior as if it's mandated by the RFC.Here's an example:
Hit
F5
a few times and after the first200
response, all subsequent responses will be304
, even though nothing in the script generates those.In
response.js
, inres.send = function send(body)
this code callsreq.fresh
, which evaluatesIf-Modified-Since
vs.Last-Updated
and if the latter is the same as the former, it drops the response and a few headers:It would be nice if discarding responses based on
req.fresh
could be disabled via application settings, similar to howetag
generation and evaluation may be disabled.If you choose not to consider this change, it would be useful if the current behavior is documented. I spent some time trying to figure out why Express silently drops a fully rendered response.
The text was updated successfully, but these errors were encountered: