Apache Mod-Python - Updated: (MODPYTHON-103) Implement req.add_output_filter().

This is Interesting: Free IT Magazines  
Home > Archive > Apache Mod-Python > January 2006 > Updated: (MODPYTHON-103) Implement req.add_output_filter().





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Updated: (MODPYTHON-103) Implement req.add_output_filter().
Graham Dumpleton (JIRA)

2006-01-07, 8:46 pm

[ http://issues.apache.org/jira/brows...ON-103?page=all ]

Graham Dumpleton updated MODPYTHON-103:
---------------------------------------

Attachment: grahamd_20060108_1_requestobject.c.diff

Attaching file "grahamd_20060108_1_requestobject.c.diff".

This is the easy bit of the suggested changes. It allows a pre registered filter to be added into either the input or output filter chain.

For example, one could do:

from mod_python import apache

def handler(req):
req.add_output_filter("CONTENT_LENGTH")
req.content_type = 'text/plain'
req.write(str(globals()),0)
req.write('\n',0)
req.write(str(locals()),0)
req.write('\n',0)
return apache.OK

Provides that no req.write() flushes the output, the "CONTENT_LENGTH" output filter provided by Apache will add a valid content length header to the response automatically.

Alternatively, if you have mod_deflate built into Apache, you could use:

from mod_python import apache

def handler(req):
req.add_output_filter("DEFLATE")
req.headers_in["Accept-Encoding"] = "gzip"
req.content_type = 'text/plain'
req.write(str(globals()),0)
req.write('\n',0)
req.write(str(locals()),0)
req.write('\n',0)
return apache.OK

This will have the effect or forcing the output sent to the browser to be compressed, ie., response header would look like:

HTTP/1.1 200 OK
Date: Sun, 08 Jan 2006 02:04:37 GMT
Server: Apache/2.0.55 (Unix) mod_python/3.2.6-dev-20051229 Python/2.3
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 1917
Connection: close
Content-Type: text/plain

The content would be compressed accordingly. Not sure if the Vary header would be an issue in this case, but no way to tell mod_deflate not to include it.

Now on to the next bit, allow filters to be registered from mod_python using req.register_input_filter() and req.register_output_filter(). The registration only being active for the current request. :-)

> Implement req.add_output_filter().
> ----------------------------------
>
> Key: MODPYTHON-103
> URL: http://issues.apache.org/jira/browse/MODPYTHON-103
> Project: mod_python
> Type: New Feature
> Components: core
> Reporter: Graham Dumpleton
> Fix For: 3.3
> Attachments: grahamd_20060108_1_requestobject.c.diff
>
> Add new member function to request object called "add_output_filter()". This would be a wrapper around the function "ap_add_output_filter()" and allow previously defined filters to be attached to the current request such that output can be filtered thro

ugh them. For example:
> req.add_output_filter("INCLUDES")
> It would probably be necessary for any such call to be done prior to the first output being generated from the request handler.
> In addition to this member function, it may be necessary to also provide another member function called something like "req.add_python_output_filter()". This would be called something like:
> req.add_python_output_filter("module_name::filter_name",path)
> Ie., like "req.add_handler()" but no first argument for phase.
> This method would allow a specific Python filter handler function to be specified. This would be equivalent to using the PythonOutputFilter directive to first name a mod_python based filter handler function and then adding it as an output filter.
> # Main Apache config.
> PythonOutputFilter module_name::filter_name MYFILTER
> # Handler code.
> req.add_output_filter("MYFILTER")
> Note that the PythonOutputFilter directive can only be used in the main Apache configuration file, it cannot be used in a .htaccess file. Whether it could be made to work in a .htaccess file in some way needs to be investigated. In mod_perl their equivl

ent seems to allow it.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com