express icon indicating copy to clipboard operation
express copied to clipboard

Make automatic 304 responses configurable.

Open mqsoh opened this issue 8 years ago • 8 comments

I needed to disable this behavior in an application I'm working on. It seemed to me that disabling ETags should disable the automatic comparing of If-None-Match and the response ETag so I opened this pull request.

@dougwilson asked that I configure this behavior specifically and I've done that here.

mqsoh avatar Jan 06 '16 23:01 mqsoh

Hi @mqsoh, I'm not sure I quite understand the scenario you have.

I would have expected disabling etags with app.disable('etag'); to result in responses with fresh being true and therefore not have status code 304.

Is there something going on that would cause this not to be the case? Or am I misunderstanding, and you are interested in not sending a 304 response whilst having etags enabled?

tunniclm avatar Jan 14 '16 15:01 tunniclm

If you disable the 'etag' feature Express will still compare an If-None-Match with the response ETag and, if they match, alter the response status to 304 and strip the body.

Usually this would be okay, but I'm dealing with some goofy clients.

mqsoh avatar Jan 14 '16 16:01 mqsoh

OK, what are they doing? Is there some middleware or route handler is setting the 'ETag' header, rather than relying on Express to do it, or setting the etag function using app.set('etag', fn);?

tunniclm avatar Jan 14 '16 17:01 tunniclm

I'm receiving if-none-match and sending an etag. Even if the cache is still valid, the client needs a 200 OK with the request body.

The problem isn't with the ETag values. I happen to be using my own. I probably could use app.set('etag', fun) instead. Even if I did, Express would still compare the etag with if-none-match, alter my status codes, and strip the body.

I actually think the behaviors are the the same. I think that disabling the etag feature should stop this behavior. I submitted a pull request with a change like that, but was asked to make it a separate setting.

mqsoh avatar Jan 14 '16 18:01 mqsoh

OK, that sounds reasonable to me.

tunniclm avatar Jan 15 '16 12:01 tunniclm

Hi @mqsoh, thank you for the pull request!

I think that the pull request is reasonable, only thinking about the name of the setting and wondering if there is a name that can be more generic without including "304" in it. Thoughts?

dougwilson avatar Jan 29 '16 18:01 dougwilson

Some suggestions:

"send not modified" "send unchanged" "send unaltered"

tunniclm avatar Feb 01 '16 14:02 tunniclm

@tunniclm suggestions are all good. Here's a couple more:

  • unmanaged etags
  • ignore etags

I have a slight preference for "automatic 304s". I think that when I was debugging my application and wondering 'Why is it sending 304s?' it would have been easy to find the answer.

"Ignore etags" is nice because it's a good description of Express's behavior when compared with the preexisting setting, i.e.

  • etag: Set the ETag response header. For possible values, see the etag options table. More about the HTTP ETag header.
  • ignore etag: When false, Express will still managed cached responses if the request's If-None-Match header is the same as the response's ETag header.

mqsoh avatar Feb 02 '16 16:02 mqsoh