Moved Permanently

The document has moved 301 Moved Permanently

Moved Permanently

The document has moved

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Server Design Week 4 Old Dominion University

Similar presentations


Presentation on theme: "Web Server Design Week 4 Old Dominion University"— Presentation transcript:

1 Web Server Design Week 4 Old Dominion University
Department of Computer Science CS 495/595 Spring 2012 Michael L. Nelson 01/31/12

2 301 Moved Permanently % telnet 80 Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/a1-test/2 HTTP/1.1 Host: Connection: close HTTP/ Moved Permanently Date: Sun, 05 Feb :12:03 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Location: Transfer-Encoding: chunked Content-Type: text/html; charset=iso 14b <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <HTML><HEAD> <TITLE>301 Moved Permanently</TITLE> </HEAD><BODY> <H1>Moved Permanently</H1> The document has moved <A HREF=" <P> <HR> <ADDRESS>Apache/ Server at Port 80</ADDRESS> </BODY></HTML> Initial 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

3 Most URI Shorteners use 301
% curl -i HTTP/ Moved Server: nginx Date: Sun, 29 Jan :24:21 GMT Content-Type: text/html; charset=utf-8 Connection: keep-alive Set-Cookie: _bit=4f25b f e1cf10a;domain=.bit.ly;expires=Fri Jul 27 21:24: ; path=/; HttpOnly Cache-control: private; max-age=90 Location: MIME-Version: 1.0 Content-Length: 168 <html> <head> <title>bit.ly</title> </head> <body> <a href=" moved here</a> </body> </html> says “Moved Permanently”

4 When is it not Permanent?
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. % cd $WWW_home % mkdir foo % touch foo/bar % lynx [returns a directory listing] % rm -rf foo % echo “this is not a directory” > foo [returns a file]

5 Status 302 Found % telnet www.techsideline.com 80
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. Status 302 Found % 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 Connection closed by foreign host. 14.30 Location The Location response-header field is used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource. … The field value consists of a single absolute URI.

6 Multiple 302s… % curl -I -L http://www.craigslist.org/
HTTP/ Found Set-Cookie: cl_b= ;path=/;domain=.craigslist.org;expires=Fri, 01-Jan :00:00 GMT Location: Content-Type: text/html; charset=iso Connection: close Location: Date: Sun, 29 Jan :09:16 GMT Set-Cookie: cl_b= ;path=/;domain=.craigslist.org;expires=Fri, 01-Jan :00:00 GMT Server: Apache HTTP/ OK Cache-Control: max-age=3600, public Last-Modified: Sun, 29 Jan 12 22:04:30 GMT Set-Cookie: cl_def_lang=en; domain=.craigslist.org; path=/; expires=Mon, 28-Jan-13 22:04:30 GMT Set-Cookie: cl_def_hp=norfolk; domain=.craigslist.org; path=/; expires=Mon, 28-Jan-13 22:04:30 GMT Transfer-Encoding: chunked Date: Sun, 29 Jan :04:30 GMT Vary: Accept-Encoding Content-Type: text/html; charset=iso ; Expires: Sun, 29 Jan 12 23:04:30 GMT

7 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.

8 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:

9 303s for DOIs % curl -I -L http://dx.doi.org/10.1145/1592761.1592794
HTTP/ See Other Server: Apache-Coyote/1.1 Location: Expires: Mon, 30 Jan :57:54 GMT Content-Type: text/html;charset=utf-8 Content-Length: 196 Date: Sun, 29 Jan :36:44 GMT HTTP/ Moved Permanently Date: Sun, 29 Jan :36:45 GMT Server: Apache/2.2.3 (Red Hat) Location: Connection: close Content-Type: text/html; charset=iso HTTP/ OK Set-Cookie: CFID= ;path=/ Set-Cookie: CFTOKEN= ;path=/ Content-Type: text/html; charset=UTF-8

10 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.

11 Proposed 308…

12 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 <HTML> <HEAD> <META http-equiv="Refresh" content="0; URL= <TITLE>Redirect to web.odu.edu...</TITLE> </HEAD> <BODY BGCOLOR=WHITE TEXT=BLACK LINK=BLUE ALINK=BLUE VLINK=BLUE> Redirect to <A HREF=" </BODY> </HTML> Connection closed by foreign host. compatible with: ? a simple robot would see a 200 and stop, but a smart robot has to peak into the entity to find http events!

13 A Simple Request… 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 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 <html> <head> <title> Michael Nelson's 1966 Ford Fairlane </title> </head> <body> […]

14 Status 304 Not Modified The 304 response MUST NOT contain a
% telnet 80 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 Content-Type: text/html <html> <head> <title> Michael Nelson's 1966 Ford Fairlane </title> </head> <body> % telnet 80 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 ETag: "1f4de dd0cc3" The 304 response MUST NOT contain a message-body, and thus is always terminated by the first empty line after the header fields. section , 14.25, RFC 2616

15 Status 412 Precondition Failed
% telnet 80 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 Transfer-Encoding: chunked Content-Type: text/html; charset=iso 159 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <HTML><HEAD> <TITLE>412 Precondition Failed</TITLE> </HEAD><BODY> <H1>Precondition Failed</H1> The precondition on the request for the URL /~mln/teaching/cs595-s06/a1-test/2/index.html evaluated to false.<P> <HR> <ADDRESS>Apache/ Server at Port 80</ADDRESS> </BODY></HTML> % telnet 80 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 Content-Type: text/html <html> <head> <title> Michael Nelson's 1966 Ford Fairlane </title> </head> <body> sections , 14.28, RFC 2616 (If-Unmodified-Since makes more sense w/ PUT)

16 Entity Tags as Conditionals
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 Transfer-Encoding: chunked Content-Type: text/html; charset=iso 159 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <HTML><HEAD> <TITLE>412 Precondition Failed</TITLE> </HEAD><BODY> <H1>Precondition Failed</H1> The precondition on the request for the URL /~mln/teaching/cs595-s06/a1-test/2/index.html evaluated to false.<P> <HR> <ADDRESS>Apache/ Server at Port 80</ADDRESS> </BODY></HTML> 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 Content-Type: text/html <html> <head> <title> Michael Nelson's 1966 Ford Fairlane </title> </head> <body> section 14.24, RFC 2616 (If-Match also makes more sense w/ PUT)

17 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 Content-Type: text/html <html> <head> <title> Michael Nelson's 1966 Ford Fairlane </title> </head> <body> 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 ETag: "1f4de dd0cc3" Connection closed by foreign host. section 14.26, RFC 2616

18 Combining Conditionals
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 ETag: "1f4de dd0cc3" Connection closed by foreign host. not true true

19 Combining Conditionals
If-Modified-Since If-Unmodified-Since If-Match If-None-Match --- undefined X 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 =


Download ppt "Web Server Design Week 4 Old Dominion University"

Similar presentations


Ads by Google