I've been tutoring kids on programming and using Free Pascal as their first computer language. I've been creating example programs to demonstrate different things computer can do and how certain technologies.
In that endeavor I've written a basic multi threaded web server as a command line application. I wanted to know if other people have done this much and it would be worthwhile for me to write up a small page with some example extensions to the web server. What is your opinion, are of this type of web server implementation and if there would be any value dedicating some time to writing up a page about it with more information.
The basic web server program which you can extend looks like this (optional clii switches include -port and binding -address):
{ A simple web server application }
program WebServer;
{$mode delphi}
uses
WebServer.Tools;
{ This is our web handler for the web server }
procedure WebHandler(Request: TWebRequest; Response: TWebResponse);
begin
{ Try to send the requested resource }
if not Response.SendFile(Request.Path) then
begin
{ If it's not found return a 404 page }
Response.Status := 404;
Response.SendFile('/404');
end;
{ Optionally print the request }
if OptionVerbose then
Request.Print;
end;
begin
{ Run the web server }
WebServerRun(WebHandler);
end.And objects to work upon the customizing your server look like this:
{ The TWebRequest class represents an http request }
type
TWebRequest = class
private
procedure Parse(const Request: string);
public
{ The raw request text sent by the client web browser }
Raw: string;
{ Method which is usually GET or POST }
Verb: string;
{ Path to the resource requested }
Path: string;
{ Optional raw query string }
Query: string;
{ Header name value pairs parsed into a handy collection }
Headers: TNamedStrings;
{ Query or form parameter name value pairs parsed into a handy
collection }
Params: TNamedStrings;
{ Print out all the information related to the request }
procedure Print;
end;