August 28, 2008

Java HTTP 1.1 Server with CGI Support

Written in 2000 for CS-476 Advanced Web Applications at Rutgers University.

Introduction

This project was to implement a server that correctly provided full support for the HTTP 1.1 protocol, including support for CGI scripts.

The server implemented closely follows the Apache model.

Theory of Operation

The stand-alone Java HTTP server called "working_server.java", will correctly do the following:

  • Implement a mini-server that generates legal HTTP 1.1 responses to HTTP/1.1 requests, and HTTP 1.0 responses for HTTP 1.0 requests.
  • Support GET, HEAD and POST methods.
  • Take the port number as its command-line parameter and listen on this port for incoming HTTP/1.1 requests.
  • Upon receiving a request, fork off a thread for processing the request and keep listening on the same port.
  • The forked off thread will generate the proper HTTP response, send it back to the browser, and terminate.
  • Process multiple requests in parallel.
  • Handle escape sequences and separators between the key-value pairs in the bodies of POST requests and query strings of the GET requests.
  • Ensure the necessary request headers are included in requests
  • Reject requests missing required headers and generate legal response headers according to HTTP 1.1
  • Use a configuration file (mime-config) that stores mappings between file extensions and MIME types.
  • Use these mappings to determine the desired Content-type for data, which is referenced by a URL specified in the GET or POST request.
  • Support basic path translation
  • Employ a basic general configuration file where you can to specify the server root, and both the document root and the cgi-bin directory relative the server root.
  • Support the execution of CGI Programs
Each of these tasks was implemented entirely in Java, and can be run on any machine which supports Java.

Source