Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Server Design Week 16 Old Dominion University

Similar presentations


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

1 Web Server Design Week 16 Old Dominion University
Department of Computer Science CS 495/595 Spring 2006 Michael L. Nelson 4/24/06

2 Common Gateway Interface
A method for remotely invoking executable programs on a server A long-time convention finally defined in RFC 3875 foo.cgi GET /foo.cgi HTTP/1.1 client server 200 OK

3 CGI Invocation How Apache does it:
We’ll live slightly more dangerously: any executable (non-directory) file can be invoked as CGI with: POST GET w/ query string e.g. /a/b/c.cgi?var1=foo&var2=bar

4 CGI Operation The CGI program is responsible for returning (on STDOUT) some combination of its own headers: Content-type Location Status and other locally-defined headers Script-returned headers are: collected by the server processed; e.g.: “Location” -> HTTP/ Found Status -> HTTP response code line combined with the server’s headers Resulting headers are returned to the client

5 Status % more status.cgi #!/usr/bin/perl
print "Status: 678 This is not a real HTTP status code\n\n"; % telnet 80 Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/cgi/status.cgi HTTP/1.1 Host: HTTP/ This is not a real HTTP status code Date: Mon, 24 Apr :37:14 GMT Server: Apache/2 Content-Length: 0 Content-Type: text/plain Connection closed by foreign host.

6 Location % more location.cgi #!/usr/bin/perl
print "Location: % telnet 80 Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/teaching/cs595-s06/cgi/location.cgi HTTP/1.1 Host: HTTP/ Found Date: Mon, 24 Apr :40:31 GMT Server: Apache/2 Location: Content-Length: 277 Content-Type: text/html; charset=iso <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>302 Found</title> </head><body> <h1>Found</h1> <p>The document has moved <a href=" <hr> <address>Apache/2 Server at Port 80</address> </body></html>

7 CGI Environment Section 4.1, RFC 3875 In practice, slightly different:
AUTH_TYPE, CONTENT_LENGTH, CONTENT_TYPE, GATEWAY_INTERFACE, PATH_INFO, PATH_TRANSLATED, QUERY_STRING, REMOTE_ADDR, REMOTE_HOST, REMOTE_IDENT, REMOTE_USER, REQUEST_METHOD, SCRIPT_NAME, SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL, SERVER_SOFTWARE In practice, slightly different:

8 How to Customize the Environment?
fork() & execve() Perl: set %ENV fork() & exec() Python: fork () & execve() Others??? please share w/ the list

9 ENV & CGI Examples {GET, POST} X {multipart/form-data,
#!/usr/bin/perl print "Content-type: text/html\n\n"; foreach $key (keys (%ENV)) { print "$key = $ENV{$key} <br>\n"; } while (<STDIN>) { print "$_<br>\n"; {GET, POST} X {multipart/form-data, application/x-form-www-urlencoded}

10 Advanced Topics: “Soft 404s”
foo.edu/lookup.php?key=123456 what http status code do you return if: script “lookup.php” exists and has no syntax errors but key is deleted or invalid Semantic events: http - 200 database - bad key reading: “Sic Transit Gloria Telae: Towards an Understanding of the Web’s Decay”


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

Similar presentations


Ads by Google