Why does the 304 status code count as a "redirect?"
Asked Answered
H

2

10

I am currently trying to understand how exactly 304/Not modified qualifies for the 3xx-range class of HTTP status codes. RFC 1945, sec. 9.3 and RFC 2616, sec. 10.3 both read:

This class of status code indicates that further action needs to be taken by the user agent in order to fulfill the request.

While "loading from the client's local cache" clearly is a "further action," I am struggling to see how this is a redirect in the sense of HTTP. Am I reading this too literally?

Huffman answered 14/5, 2014 at 6:22 Comment(0)
P
8

See http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p2-semantics-26.html#rfc.section.6.4.p.2:

There are several types of redirects:

  1. Redirects that indicate the resource might be available at a different URI, as provided by the Location field, as in the status codes 301 (Moved Permanently), 302 (Found), and 307 (Temporary Redirect).

  2. Redirection that offers a choice of matching resources, each capable of representing the original request target, as in the 300 (Multiple Choices) status code.

  3. Redirection to a different resource, identified by the Location field, that can represent an indirect response to the request, as in the 303 (See Other) status code.

  4. Redirection to a previously cached result, as in the 304 (Not Modified) status code.

Piroshki answered 14/5, 2014 at 6:44 Comment(2)
Thanks for the link. It is interesting to see that 304 is listed in an entirely different section. So the semantics really are "redirect to locally cached copy?" Otherwise I really wouldn't know why "Not modified" can't be a 2xx-class code such as 201/Created (which can redirect as well) or 204/No content. After all, the request has been successful.Huffman
Yes, "If-Modified-Since" header explicitly tells the server "I know this resource exists, and I know how to represent it, had it modified since last time I knew it?" - The server will reply with either "304 Not modified", or a more appropriate code, such as "200 Ok" (new version of the content) or "404 Not found", or whatever else appropriate for the moment.Convulse
M
3

I imagine it is because the server is "redirecting" the client to load the requested resource from its local cache instead of downloading it from the server. If the client did not have a local cached copy then it should not be sending a conditional request in the first place.

Multiplicity answered 14/5, 2014 at 6:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.