mod_python PythonFixupHandler

58 views
Skip to first unread message

Noorul Islam Kamal Malmiyoda

unread,
Oct 16, 2012, 7:04:25 AM10/16/12
to mod...@googlegroups.com
I have a requirement to re-write response data before sending to the browser. It was easily achieved using PythonFixupHandler of mod_python. Is there an equivalent one in mod_wsgi? Did someone try to do something similar using mod_wsgi? There is a thread https://groups.google.com/d/topic/modwsgi/Skx9B1dEKxM/discussion which discusses about PythonFixupHandler but OP's requirement is something else.

Thanks and Regards
Noorul

Graham Dumpleton

unread,
Oct 16, 2012, 7:24:47 PM10/16/12
to mod...@googlegroups.com
On 16 October 2012 22:04, Noorul Islam Kamal Malmiyoda
Can you post the code for your fixup handler.

A fixup handler is run before the content handler in mod_python and so
it can't actually be used to change the response data (content) from a
content handler. So what you mean by response data is confusing.

Graham

Noorul Islam Kamal Malmiyoda

unread,
Oct 17, 2012, 10:04:49 PM10/17/12
to mod...@googlegroups.com
On Wednesday, October 17, 2012 4:54:49 AM UTC+5:30, Graham Dumpleton wrote:
Can you post the code for your fixup handler.

A fixup handler is run before the content handler in mod_python and so
it can't actually be used to change the response data (content) from a
content handler. So what you mean by response data is confusing.



def fixuphandler(req):
    req.register_output_filter("LOCATIONFIXUP", location_fixup)
    req.add_output_filter("LOCATIONFIXUP")

def location_fixup(filter):
    // Code to read contents from filter and do the necessary changes.
            temp_doc = filter.req.temp_doc
            s = filter.read()
            while s:
                temp_doc.append(s)
                s = filter.read()
            if s is None:
                page = ''.join(temp_doc)

            page = filter_html(page, filter_proxy_uri_base,
                                   "/%s/%s" % (hum_loc, hum_key),
                                   proxy_host, server_name, aggr_level,
                                   tag_debug)
             filter.write(page)
             filter.close()

filter_html is the function which processes the html content.

Thanks and Regards
Noorul

Graham Dumpleton

unread,
Oct 19, 2012, 10:47:14 PM10/19/12
to mod...@googlegroups.com
What is generating the content that is going into this filter?

The mod_wsgi package doesn't provide an ability to write Apache output
filters. All you could do is write a WSGI middleware for a Python WSGI
application to perform fixups on any response content. Such a method
will only work for Python WSGI applications and it cannot be used
where the request content is coming from static files or other Apache
handlers which are generating dynamic content. Even if a Python WSGI
application is generating the request content, writing WSGI middleware
to perform such fixups is not a simple exercise if want the middleware
to be compliant with the WSGI specification in all ways.

Graham

On 18 October 2012 13:04, Noorul Islam Kamal Malmiyoda
> --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/modwsgi/-/YXRGRAnt-3MJ.
>
> To post to this group, send email to mod...@googlegroups.com.
> To unsubscribe from this group, send email to
> modwsgi+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/modwsgi?hl=en.

Graham Dumpleton

unread,
Oct 19, 2012, 10:49:07 PM10/19/12
to mod...@googlegroups.com
BTW, you may also want to investigate:

http://httpd.apache.org/docs/2.4/mod/mod_sed.html

as an alternative for modifying response content.

Graham
Reply all
Reply to author
Forward
0 new messages