Web Server Design Week 4 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/03/10
Status 301 Moved Permanently Main use: redirect requests for directories not ending in a “/” Can be configured for other resources Browsers typically handle 301 (and 302, 303 & 307) transparently mk$ telnet 80 Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mklein/teaching/cs595-s10/a1-test/2 HTTP/1.1 connection: close host: HTTP/ Moved Permanently Date: Tue, 02 Feb :56:32 GMT Server: Apache/ (Unix) DAV/2 PHP/ Location: Content-Length: 362 Connection: close Content-Type: text/html; charset=iso Moved Permanently Moved Permanently The document has moved here. Apache/ (Unix) DAV/2 PHP/ Server at Port 80 Connection closed by foreign host.
When is it not Permanent? % cd $WWW_home % mkdir foo % touch foo/bar % lynx [returns a directory listing] … % rm -rf foo % echo “this is not a directory” > foo % lynx [returns a file] Moved Permanently The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs.
Status 302 Found Found The requested resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only cacheable if indicated by a Cache-Control or Expires header field. The temporary URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s). If the 302 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued. Note: RFC 1945 and RFC 2068 specify that the client is not allowed to change the method on the redirected request. However, most existing user agent implementations treat 302 as if it were a 303 response, performing a GET on the Location field-value regardless of the original request method. The status codes 303 and 307 have been added for servers that wish to make unambiguously clear which kind of reaction is expected of the client. % telnet 80 Trying Connected to Escape character is '^]'. GET / HTTP/1.1 Host: HTTP/ Found Date: Sun, 04 Feb :29:13 GMT Server: Apache Set-Cookie: PHPSESSID=1ea69c374ee8ee5c8df78e8c4105cc3e; expires=Sun, 18 Feb :29:18 GMT; path=/; domain=techsideline.com Expires: Thu, 19 Nov :52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Location: /home Connection: close Transfer-Encoding: chunked Content-Type: text/html 0 Connection closed by foreign host.
303 See Other The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource. The 303 response MUST NOT be cached, but the response to the second (redirected) request might be cacheable. The different URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s). Note: Many pre-HTTP/1.1 user agents do not understand the 303 status. When interoperability with such clients is a concern, the 302 status code may be used instead, since most user agents react to a 302 response as described here for 303.
Cool URIs For The Semantic Web 303 Redirection has been retroactively claimed for supporting using http URIs for identifying “real world objects” (not just web pages about real world objects) –see:
307 Temporary Redirect The requested resource resides temporarily under a different URI. Since the redirection MAY be altered on occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only cacheable if indicated by a Cache-Control or Expires header field. The temporary URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s), since many pre-HTTP/1.1 user agents do not understand the 307 status. Therefore, the note SHOULD contain the information necessary for a user to repeat the original request on the new URI. If the 307 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.
Pseudo-HTTP Redirection % telnet list.odu.edu 80 Trying Connected to list.odu.edu. Escape character is '^]'. GET / HTTP/1.1 Host: list.odu.edu HTTP/ OK Date: Sun, 04 Feb :28:07 GMT Server: Apache Last-Modified: Tue, 02 Aug :21:52 GMT ETag: "3d3c9-17d-3b2fbc00" Accept-Ranges: bytes Content-Length: 381 Content-Type: text/html; charset=ISO Redirect to web.odu.edu... Redirect to Connection closed by foreign host.
A Simple Request… Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. HTTP/ OK Date: Sun, 05 Feb :58:27 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Last-Modified: Sun, 29 Jan :43:15 GMT ETag: "1f4de dd0cc3" Accept-Ranges: bytes Content-Length: 1936 Connection: close Content-Type: text/html Michael Nelson's 1966 Ford Fairlane […] If the resource is large, we might not want to grab the whole thing frequently unless it has changed We could combine HEAD & GET, or we can modify our request with additional headers
Status 304 Not Modified AIHT.local:/Users/mln/Desktop/cs595-s06 % telnet 80 | tee 5-2.out Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/a1-test/2/index.html HTTP/1.1 Host: Connection: close If-Modified-Since: Sun, 29 Jan :43:15 GMT HTTP/ Not Modified Date: Sun, 05 Feb :58:41 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Connection: close ETag: "1f4de dd0cc3" AIHT.local:/Users/mln/Desktop/cs595-s06 % telnet 80 | tee 5-3.out Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/a1-test/2/index.html HTTP/1.1 Host: Connection: close If-Modified-Since: Sun, 29 Jan :43:14 GMT HTTP/ OK Date: Sun, 05 Feb :58:52 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Last-Modified: Sun, 29 Jan :43:15 GMT ETag: "1f4de dd0cc3" Accept-Ranges: bytes Content-Length: 1936 Connection: close Content-Type: text/html Michael Nelson's 1966 Ford Fairlane section , 14.25, RFC 2616
Status 412 Precondition Failed AIHT.local:/Users/mln/Desktop/cs595-s06 % telnet 80 | tee 5-5.out Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/a1-test/2/index.html HTTP/1.1 Host: Connection: close If-Unmodified-Since: Sun, 29 Jan :43:15 GMT Connection closed by foreign host. HTTP/ OK Date: Sun, 05 Feb :01:54 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Last-Modified: Sun, 29 Jan :43:15 GMT ETag: "1f4de dd0cc3" Accept-Ranges: bytes Content-Length: 1936 Connection: close Content-Type: text/html Michael Nelson's 1966 Ford Fairlane AIHT.local:/Users/mln/Desktop/cs595-s06 % telnet 80 | tee 5-7.out Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/a1-test/2/index.html HTTP/1.1 Host: Connection: close If-Unmodified-Since: Sun, 29 Jan :43:14 GMT HTTP/ Precondition Failed Date: Sun, 05 Feb :02:22 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=iso Precondition Failed Precondition Failed The precondition on the request for the URL /~mln/teaching/cs595-s06/a1-test/2/index.html evaluated to false. Apache/ Server at Port 80 0 sections , 14.28, RFC 2616
Entity Tags as Conditionals AIHT.local:/Users/mln/Desktop/cs595-s06 % telnet 80 | tee 5-8.out Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/a1-test/2/index.html HTTP/1.1 Host: Connection: close If-Match: "1f4de dd0cc3" HTTP/ OK Date: Sun, 05 Feb :07:12 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Last-Modified: Sun, 29 Jan :43:15 GMT ETag: "1f4de dd0cc3" Accept-Ranges: bytes Content-Length: 1936 Connection: close Content-Type: text/html Michael Nelson's 1966 Ford Fairlane … AIHT.local:/Users/mln/Desktop/cs595-s06 % telnet 80 | tee 5-9.out Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/a1-test/2/index.html HTTP/1.1 Host: Connection: close If-Match: "1f4de dd0cc2" HTTP/ Precondition Failed Date: Sun, 05 Feb :07:21 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=iso Precondition Failed Precondition Failed The precondition on the request for the URL /~mln/teaching/cs595-s06/a1-test/2/index.html evaluated to false. Apache/ Server at Port 80 0 section 14.24, RFC 2616
Getting Fancy With Etags… AIHT.local:/Users/mln/Desktop/cs595-s06 % telnet 80 | tee 5-11.out Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/a1-test/2/index.html HTTP/1.1 Host: Connection: close If-None-Match: "1f4de dd0caa" HTTP/ OK Date: Sun, 05 Feb :10:00 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Last-Modified: Sun, 29 Jan :43:15 GMT ETag: "1f4de dd0cc3" Accept-Ranges: bytes Content-Length: 1936 Connection: close Content-Type: text/html Michael Nelson's 1966 Ford Fairlane AIHT.local:/Users/mln/Desktop/cs595-s06 % telnet 80 | tee 5-12.out Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/a1-test/2/index.html HTTP/1.1 Host: Connection: close If-None-Match: "1f4de dd0caa”, "1f4de dd0cc3" HTTP/ Not Modified Date: Sun, 05 Feb :10:13 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Connection: close ETag: "1f4de dd0cc3" Connection closed by foreign host. section 14.26, RFC if method != GET, HEAD Server will respond if (one) Etag matches and If-Modified-Since header triggers
Combining Conditionals not true true AIHT.local:/Users/mln/Desktop/cs595-s06 % telnet 80 | tee 5-14.out Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/a1-test/2/index.html HTTP/1.1 Host: Connection: close If-Modified-Since: Sun, 29 Jan :43:15 GMT If-Match: "1f4de dd0cc3" HTTP/ Not Modified Date: Sun, 05 Feb :02:18 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Connection: close ETag: "1f4de dd0cc3" Connection closed by foreign host.
Combining Conditionals If-Modified-SinceIf-Unmodified- Since If-MatchIf-None-Match If-Modified-Since--- If-Unmodified- Since undefined--- If-MatchundefinedX--- If-None-MatchXundefined --- If the request normally (i.e., without the *** header) would result in anything other than a 2xx or 412 status, the **** header SHOULD be ignored. X =