View on GitHub

SampleProxy

Vert.x implementation of a filtering HTTP proxy with loadable content filters

Filtering Proxy

Sample application of a configurable filtering Proxy based on work by Julien Viet.

How it works

The whole setup is configured in proxy.json that needs to be available in the root of the application. The basic settings are:

Requests from the client are passed without modification to the target host. The response gets matched against any of the defined filters by mime type and path (optional Regex). The filter then converts the byte stream into a mime type specific format and hands it to each subfilter for processing.

A subfilter should do one filtering task only. Subfilters can be applied multiple times using different configuration settings. E.g. the DropTag filter can be used to clear different HTML tags by configuring it multiple times with different tag names.

Filter definition

A filter definition has a shared set of properties:

Subfilter definition

A subfilter performs the actual filtering work. Currently there are subfilters for HTML (using a JSoup HTML document), JSON (using a JsonObject) and Text (using String). To work the following parameters are needed:

Available Filters and subfilters

net.wissel.vertx.proxy.filters.HtmlFilter

Takes in a HTML page. When the original page is sent HTTP junked, it combines the junks and renders a JSoup document. The JSoup document is passed to the subfilters for processing. Current subfilters:

net.wissel.vertx.proxy.filters.JsonFilter

Processes JSON resources by converting them to a JsonObject (careful when server serves large amount of Json). Current subfilters: The available handler derive from the AbstractElementHandler and differ in the way how they select the elements to act on. Easy to extend

net.wissel.vertx.proxy.filters.SimpleElementHandler

Required parameters:

For more complex queries including value comparison, use XpathElementHandler

net.wissel.vertx.proxy.filters.XpathElementHandler

Required parameters:

net.wissel.vertx.proxy.filters.XsltElementHandler

Transforms the incoming Json to XML (see here), applies a stylesheet and transforms it back. It’s the responsibility of the stylesheet writer to provide a result that can be translated back. Can be used for complex manipulations (or keyword replacements) ;-) Required parameters:

net.wissel.vertx.proxy.filters.TextFilter

Processes a plaintext file. Hands a String to the subfilters Current subfilters:

Create your own Subfilters

There are Interfaces available that have one method only. To implement your own subfilter implement one of these interfaces. Each subfilter needs a constructor that takes a JsonObject as parameter for its configuration (even if it doesn’t used them). Available interfaces:

Ideas

This is a capability demo. So extensions make sense. Some ideas: