Server-side:
The Server

Parke Godfrey
28 September 2012
CSE-2041

Credits

These slides are based in part on ones from the following sources.

The HTTP Session

KISS: Keep It Short & Simple

The Daemon Loop


Important! The server is listening for other processes while servicing existing sessions.

However, there is a limit to the number of open sessions.

Serving Static Content

  1. Listen on port 80.

  2. Fork to handle when an HTTP request arrives.

  3. Extract the path/file from the URL.

  4. Check whether file exists.
    If not, return status 404.

  5. Check whether File is reachable & readable (chmod).
    If not, return status 403.

  6. Determine the content type.

  7. Return with status 200 (OK) and a type header.

  8. Serve file as the payload.

  9. Close HTTP session.
    Or, on keep-alive, wait brief time for another request.

HTTP Status / Response Codes

Status codes are part of the HTTP protocol.

  1. 100 series
    • Sessional update from server.
  2. 200 series
    • Success!
  3. 300 series
    • Redirect.
  4. 400 series
    • Client error.
  5. 500 series
    • Server error.

LAMP
a common Web-server stack

We will use Apache running on Linux as our working model.

Serving Static Content
other considerations

Types of Dynamic Content

Serving Dynamic Content
CGI

Same as static up to Step #4. 

  1. Check that file is reachable.  (Readable not needed!)
    If not, return status 403.

  2. Masquerade as file owner.

  3. Check that file is executable by owner.
    If not, return status 500.

  4. Run the file and capture its output.

  5. Check the validity of the output.

    1. Not valid? Return status 500.

    2. Valid? Return status 200 (OK), and the output as the payload.

Building a Server

Hey, this looks easy!