Project Description

Portable and small HTTP server written on C++, supported Windows/Linux.
Has handlers/modules architecture - developed Python handler (WSGI), ASP.NET (Win32)/ISAPI extensions handler, FastCGI handler, BASIC authentication module.
Supported chunked/gzip/deflate response encodings
Generally this project is result of my creative investigation of modern C++ programming approaches. When I started this project at my commercial work I could not satisfy my curiosity and taste for new programming technologies learning and it was root cause of this project creation - I have started it to refresh/extend and fix my C++ skills.

HTTP server application was selected as a complex set of functional parts:
* TCP sockets + HTTP protocol;
* parallel HTTP requests processing (multi-threading);
* interaction with server file system;
* modular architecture (plug-ins/modules support);
* server-side scripting support;
* server application features (service/daemon);
* errors logging/server control.

Also several targets were selected at project beginning:
  1. Code must be portable (project should be compiled/run at least under Windows and Linux) - right now I have tested it on Windows XP and Ubuntu Linux 7.10.
  2. Code should be organized in independent parts which can be reused in other projects.
  3. Project code have to be as small as possible (known C++ libraries can be utilized).

At present ahttpserver project contains three main parts:
  • aconnectlib static library - contains multithreaded TCP server implementation, file logger, and great amount of utility functionality - TCP socket control, string processing algorithms, date/time functions, cryptography;
  • ahttplib static library - HttpServer class definition and all HTTP requests parsing/processing functionality;
  • ahttpserver - server application core.

To extend server features set of plugins was developed:
  • handler_aspnet - ASP.NET application support (available only under Windows). Common architecture of this plugin was copied from .NET Cassini server;
  • handler_isapi - IIS ISAPI extensions wrapper - using this wrapper ahttpserver can utilize already developed ISAPI extensions to support different script engines. This handler works correctly with PHP 4, I have tried to use ASP and ASP.NET ISAPI extensions but both of them uses undocumented features of IIS and cannot be loaded into ahttpserver;
  • handler_python - Python scripts support, works differently from general approach to server-side Python - this module executes scripts directly or through WSGI interface;
  • handler_fastcgi - FastCGI bridge - allows to connect FastCGI-enabled engines to ahttpserver, currently implemented only for Windows platform (tested with PHP 5.3.1);
  • module_authbasic - Basic authentication support - two types of auth. providers available. Server provider authenticates users against list loaded from file and system provider (now works only under Windows) authenticates users against OS.

Code samples see at Using the Code.

ahttpserver features

At present ahttpserver has following features:
  • HTTP methods GET/POST/HEAD.
  • Internal logic to POST parameters parsing + uploaded files processing ("multipart/form-data" request type) - this functionality can be used in custom handlers implementation.
  • Keep-alive mode.
  • "chunked" transfer encoding - support for dynamically created response.
  • "gzip"/"deflate" content encoding.
  • MIME type evaluation by file extension (mime-types.config).
  • Automatic URL mapping - (see sample in web\directory.config).
  • Default documents loading (index.html).
  • Directories browsing with customizable UI.
  • Handlers/modules architecture - provide easy way to extend server functionality.
  • "If-Modified-Since" header support - decrease server filesystem overload.
  • "Accept-Ranges" header support - used to partial content download.

Project dependencies

  • Boost 1.38 is required to compile ahttpserver sources.
  • To get 'gzip'/'deflate' encodings support zlib 1.2.3 library should be installed (you can avoid zlib usings by commenting out ACONNECT_USE_ZLIB definition in aconnectlib\aconnect\config.hpp).
  • To play with Python interpreter Python 2.5+ should be installed. To deny Python handler load - remove all "handlerpython" dependencies from server.config_ file.

Possible using scenarios

  • Hosting set of ASP.NET applications on developer's machine especially under Windows XP to get rid of 403 errors bunch, each application can be hosted as root application (CMS like Umbraco). This behavior is supported in two modes:
    • dedicated ahttpserver instance (ahttpserver.exe, handler_aspnet.dll and server.config) used to run each application on separate TCP port simultaneously;
    • applications hosting rules defined in two or more configuration files and switched (with server restarting) to run each application in turn. Using IIS 5/6 to manage several root applications on require much more work.
  • Development of Python-based web-applications supported WSGI, for example based on Django framework, each WSGI application can be hosted in separate virtual directory (see example in sources: out/doc/config/samples/python-wsgi-django/).
  • Creation intranet company-specific HTTP applications with custom authentication/requests processing functionality (by new handlers implementation or ahttpserver sources update).
  • Using ahttp library to create small embedded HTTP servers for portable/low memory devices under Win32/Linux platforms.

Server application management

Server configuration file format see at Configuration.
  • To start server go to the server directory and run 'ahttpserver.exe start'.
  • To see server statistics run 'ahttpserver.exe stat'.
  • To reload server configuration file (only directories info will be refreshed) run 'ahttpserver.exe reload' - it can be used to add/remove virtual directories without complete server application stopping.
  • To stop server run 'ahttpserver.exe stop'.

See more details at following sources:
http://www.codeproject.com/KB/cpp/ahttpserver.aspx
http://www.codeproject.com/KB/cpp/ahttpserver_dotnet.aspx

Last edited Jan 4, 2010 at 10:32 PM by artiz, version 12