viksoe.dk

HTTP Proxy


This article was submitted .


This component is a module that fits in with my Client / Server sample.

The idea is that once you've written your application server, someone (usually a sales-dude) will ask you if it's possible to access the information over the internet (through a web server; a HTTP request).
You've already build networking into your application server, so you could add another HTTP protocol layer and have the server moved to the machine with the web server. But why do the extra work? Why not have the web server come to you? Why not route the request to your application while converting the data stream from your application specific protocol to a HTTP response?

So the grand picture is that you keep the server as it is - but modifies the web server to transform incoming HTTP requests into the communication protocol already defined and supported by your server.
The web server listens for the application server's answer and turns it into a HTTP response by formatting it to a MIME format. It's actually a bit like a simple SOAP implementation (without the method invocation... and the XML if you don't like that... and without a lot of all the other cool things you can do with SOAP).

Most web servers support some kind of extension API. With Microsoft Internet Information Server (IIS) it's the ISAPI module.

The ISAPI module

I've written an ISAPI extension, which intercepts requests to the web server. The request is embedded in the URL with which the client does a HTTP GET to the web server. Then the ISAPI module dismantles the request, turns it into messages to the application server through a normal IP connection and delivers the response back in the original HTTP request.
The same stuff could actually have been implemented using a simple ASP page, but since this is a C++ sample, I'm writing it as an ISAPI module.

The Code

This source code is actually pretty simple. I used the MFC AppWizard to create an ISAPI module and simply included my general network wrapper classes to the project.
The ISAPI module defines two URL commands: Get and Set. The commands are invoked simply by requesting the ISAPI DLL to run from a web request, like this:
http://Server/Scripts/ServerProxy.dll?Set&Item&Value
http://Server/Scripts/ServerProxy.dll?Get&Item
The module catches the request, generate a response (as a HTML page) and sends it back. It didn't have to be a HTML page, it could have been an XML document or something nice, but for now it is a HTML page. The MFC classes for writing ISAPI modules hides all the nasty stuff about parsing URL arguments and generating HTML responses. This allows you to quickly develop more complicated responses.
The latest version of Visual C++ even includes the same classes in a high-performance ATL version.

The response page in this case either contains the requested value or an error code. The client must interpret this information by parsing the HTML content.

Security and Scalability

There are two major advantages with building this seemingly complex system.

Security

The added security comes from the fact that you do not place the application server on the web server.

The real security bonus comes when firewalls are added. Most companies have firewalls in front of their web-server. Some companies also have a firewall between the web-server and their local network. The second firewall denies all access between the web server and the rest of the network except for specific IP ports. One such IP port would be the port the ISAPI module uses to communicate with the application server.
Hackers that succeed in getting past the outer firewall will have real trouble getting through the second firewall because they first need to decipher the communication protocol the ISAPI module uses between the application server.

Scalability

One obvious advantage is that the web-server is relieved from doing any processing locally. The web-server simply forwards the request to the application server.
In fact, the web-server could forward requests to a pool of application servers. Having multiple application servers could scale the system tremendously if each application server needs to do any lengthy processing of each request.

Source Code Dependencies

Microsoft Visual C++ 6.0
Internet Information Server 5.0
Microsoft MFC Library

Installation Guide

  • Edit the install.reg file and execute it.
  • Compile and copy the DLL to the Inetpub\Scripts folder.

Download Files

DownloadISAPI Module (Server sample) (65 Kb)

To the top