[mod_python] PSP handler forces content_type text/html ; can this be overridden?

Graham Dumpleton graham.dumpleton at gmail.com
Sat Mar 22 18:04:51 EDT 2008


On 23/03/2008, Sidney Cadot <sidney.cadot at jigsaw.nl> wrote:
> Hi all,
>
>  I'm trying to use mod_python's PSP handler to emit XHTML (content-type:
>  "application/xhtml+xml"). Unfortunately, the PSP implementation forces the
>  request's content_type to "text/html".
>
>  Is there a way to override this?

Depends on how you are invoking it.

If using:

  PythonHandler mod_python.psp .psp

replace with:

  PythonHandler mypspwrappermodule .psp

where you define a module mypspwrappermodule which contains:

  from mod_python import psp

  def handler(req):

    req.content_type = "application/xhtml+xml"

    config = req.get_config()
    debug = debug = int(config.get("PythonDebug", 0))

    if debug and req.filename[-1] == "_":
        p = psp.PSP(req, req.filename[:-1])
        p.display_code()
    else:
        p = psp.PSP(req)
        p.run()

    return apache.OK

If using PSP() object directly already and doing str() on it to force
execution, then don't do that and look at implementation of __str__()
of PSP object instance and do something similar but set different
content type, ie., much like above, set content type and then call
run().

Graham


More information about the Mod_python mailing list