[mod_python] A cheap handler for exploring Apache req contents

Sean True seant at alum.mit.edu
Mon Jun 5 23:11:07 EST 2000

The following code is so inelegant, I'm a little embarrassed to share it, 
but it's a handy handler for starting
to poke around inside the Apache req structure, and so informative that I 
thought I'd share.

Grisha might want to comment as to why some of the attributes of the req 
don't dump the way I tried to dump them. Could just be the late night 
stupids on my part.

-- Sean

from mod_python import apache

def dumpdict(req,title, d):
     req.write("*"+title + "\n")
     for key in d.keys():
         req.write(str(key) + ": " + str(d[key]) + "\n")
def dump(req,title,s):
     req.write(title+": "+s+"\n")
def handler(req):
     dump(req,"Request", req.the_request)
     dump(req,"Protocol", req.protocol)
     dump(req,"Hostname", req.hostname)
     dump(req,"Status line", req.status_line)
     dump(req, "Method", req.method)
     dump(req,"Content handler", req.handler)
     dump(req, "Unparsed uri", req.unparsed_uri)
     dump(req, "Uri", req.uri)
     dump(req, "Filename", req.filename)
     dump(req, "Path info", req.path_info)
     dump(req, "Args", req.args)
     dump(req, "Mtime", str(req.mtime))
     dump(req, "Remaining", str(req.remaining))
     # The following don't work.
     #dump(req, "Content type", req.content_type)
     #dump(req, "Content encoding", req.content_encoding)
     #dump(req, "Parsed uri", str(req.parsed_uri))
     #dump(req, "finfo", str(req.finfo))
     dumpdict(req, "headers_in",req.headers_in)
     dumpdict(req, "headers_out", req.headers_out)
     dumpdict(req, "err_headers_out", req.err_headers_out)
     dumpdict(req, "subprocess_env", req.subprocess_env)
     dumpdict(req, "notes", req.notes)
     return apache.OK
Output on my system: (with domain deleted for privacy)
Request: GET /foo.xhtml?fu=bar HTTP/1.0
Protocol: HTTP/1.0
Hostname: www.[..].com
Status line: 200 OK Method: GET
Content handler: python-program
Unparsed uri: /foo.xhtml?fu=bar
Uri: /foo.xhtml
Filename: /usr/local/apache/htdocs/foo.xhtml
Path info:
Args: fu=bar
Mtime: 0
Remaining: 0
Accept: */*
Accept-Language: en-us
Connection: Keep-Alive
Host: www.[..].com
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)
Connection: close
Content-Type: text/plain
SCRIPT_URL: /foo.xhtml
SCRIPT_URI: http://www.[..]/foo.xhtml
REQUEST_URI: /foo.xhtml?fu=bar
SCRIPT_NAME: /foo.xhtml
python_request_ptr: 135846824

Sean True
seant at alum.mit.edu

More information about the Mod_python mailing list