Manipulating HTTP requests through Apache Filters
Source: httpd.apache.org

Manipulating HTTP requests through Apache Filters

I have been performing an architectural assessment and re-mediation of a large enterprise application for a Government of India Financial Services Firm. This is a huge system integration project consisting of 12+ applications, including Core Insurance, Financials, HRMS, CRM and others, integrated using a commercial SOA platform.

Apache Web servers are used as a proxy into the various application servers. We had implemented a structured logging mechanism and I had written a Python program that processes all the logs in various application servers to produce summarized data to understand performance and scalability issues.

One very critical feature we needed was to be able to print a particular XML element, that is part of the SOAP request in the Apache access logs. While it is easy to print the http headers in the Apache access log through the %{element-name} feature in httpd.conf, Apache does not have any native capability to parse XML and print an element in its access log.

I developed an Apache Input filter using its C-API. This filter applies its logic only when the requests are POST requests and the Content-Type is text/xml, which is always the case with SOAP requests. It then extracts a particular element from within the SOAP payload and injects a HTTP header into the request. This enables this element to be logged as part of the Apache access log.

Since there is no IP restriction on this program (being a simple utility to get some data as part of the Performance Testing environment), I have uploaded it in github (https://github.com/umakanthdiwakar/ApacheAuditFilter). The program will "mostly" work, with one small quirk to make it interesting. If anyone has a need for custom content manipulation in Apache, feel free to use it as a base. I will be glad to help you out if you get stuck.

Here are some simple steps to create a skeleton Apache module. Let us assume that apache is installed in /usr/local/apache2. Let us also assume that you want to create a filter called as myfilter.

$ cd /usr/local/apache2

$ bin/apxs -g -n myfilter

$ cd myfilter

$ vi mod_myfilter.c

Perform your edits of the file here. Please refer apache documentation to understand the purpose of each function in the skeleton.

$ ../bin/apxs -c -i mod_myfilter.c

This will compile and deploy your module as a shared library in the "modules" directory.

Now add the following line to httpd.conf

LoadModule module_myfilter modules/mod_myfilter.so

To view or add a comment, sign in

More articles by Umakanthan Diwakaran

  • Dart the failure! Will it drag Flutter down with it?

    Dart as you are all aware, started as the next JavaScript and then ultimately landed in a place far lower than…

    1 Comment
  • Kubernetes vs Docker EE business

    When your technology succeeds, but you fail as a business! Seen it often? A good example would be Docker. Docker the…

    1 Comment
  • Getting a grasp of Scaled Agile (SAFe)

    If you always wanted to learn SAFe, but were always put-off by that big complex diagram describing SAFe and by all the…

  • The agile manifesto - in more words

    Agile does NOT mean, NOT documenting and NOT thinking through. Even if you are following an agile methodology, it is…

  • DARTing towards oblivion.

    There are some very sound languages and technologies, that are doomed to fail for a significant period of their…

  • Otto - A gem of a JS runtime

    Even for a software craftsman, an opportunity to single-handedly take a product from concept to code and on-to…

  • Dear Leadership exponents; please leave nature alone.

    Just viewed one more "what we can learn about leadership from X". This time that X was the eagle.

  • Faster GO API development through rapid generation of database access layer

    GO with Postgres is a fantastic platform to build micro-services. GO provides a "sql" API standard for accessing…

  • Microservices are not micro-services

    It would be hard to find another term, that has done so much disservice to an architectural approach as the term…

    3 Comments
  • "GO" for Gold

    Having worked across several languages, starting with C & assembly, moving on to C++ and Java, adding .Net later along…

Others also viewed

Explore content categories