mapproxy/mapproxy — pull request #73 by walkermatt (2013-03-22 13:47:56+00:00)
Title: Callback to allow ImageSource to be updated by WSGI middleware

Hi,

Spoke briefly to @olt about this on irc a few weeks ago. My main use case for this is applying a graphic watermark based on the request path (one common cache with a different watermark for each organisation using the service).

I originally implemented the watermarking using a WSGI filter that called MapProxy, loaded the response into an Image, applied the watermark then streamed the new buffer and updated the Content-Length header. This works but is slow and a little involved. This alternative approach allows a WSGI filter to register a callback which is passed the ImageSource that it can simply modify before leaving it up to MapProxy to generate the response.

Adds postprocess_image method to the base Server that allows WSGI
middleware to post process the ImageSource prior to it being returned in
the response. Commonly used for applying a graphic watermark or applying
a filter to the image.

The callback is associated with the key mapproxy.postprocess in the WSGI
environment. It is passed the ImageSource and is expected to return an
ImageSource.

The postprocess_image method is called from service/wms and service/tile
prior to the ImageSource being returned in a response.

Added unit tests for postprocess_image method.