mod_cplusplus for Apache-2.0

Written by John K. Sterling

Helpful Links:
  • Donate to the developers
  • Download
  • API Docs
  • View the CVS tree
  • Project Page
  • What is it?

    Easily implement object oriented apache-2.0 handlers with C++ including all the standard phases of the request cycle, input filters, output filters, and protocol handlers.
    This is a big improvement for a number of reasons:

  • C++ modules now only need pure C++, with no kludges to allow apache hooks to invoke C++ methods.
  • All request phases and filtering phases are exposed cleanly through object oriented method invocations.
  • The core structures (e.g. request_rec) are objectified to encapsulate functionality and provide a clean api.
  • Because mod_cplusplus only instanciates your objects once per server, you can easily cache re-used data in the object and all requests to that child will benefit.

  • Simply subclass from the included baseclasses (e.g. ApacheHandler) and implement whichever phases of the request you are interested in (e.g. check_user_id()) and point mod_cplusplus at it in the config file. No need to hack your own module structure to proxy calls to your objects.

    Getting Started

  • make sure you have apache-2.0 installed
  • download mod_cplusplus
  • ./configure --with-httpd=/path/to/apache2
  • make && make check

    Make check will fire up apache, install the modules from the example/ directory, and perform some request to verify they are all working. You can use these examples and the config snippets in test/t/conf/extra.conf to get started on your own.

    What does a handler look like?

    This example implements a content handler:
    LoadCPPHandler test_handler

    #include "apache_handler.h"
    class TestHandler : public ApacheHandler
        TestHandler(void) { };
        ~TestHandler(void) { };
        int handler(ApacheRequestRec *pRequest);
    int TestHandler::handler(ApacheRequestRec *pRequest)
        pRequest->rprintf("\nThis handler is called for user %s", pRequest->user())
        pRequest->rputs("\nLets Dump The Request!\n");
        return OK;

    ================================================= Logo