Getting POST data from mod_perl2

I learned today after spinning my wheels a lot over the last few days that mod_perl2 under apache can parse POST data only once. I tried any number of ways to get at the POST data, but it was always empty. Finally, I came across something that mentioned that POST data could be parsed only once. The module I’ve been working on was running at the PerlLogHandler phase, which is after the request had already been parsed. So I could try all I wanted to re-parse the POST content, but I was parsing something that didn’t exist. When I attached the module to the earlier PerlHeaderParserHandler request phase (more info on this stuff here), I had access to the POST data. Of course, my grabbing the POST data in this phase makes it unavailable to other phases, which means that if a PHP file in the directory the module screws with tries to access the $_POST array, it’ll be empty and the script probably won’t behave as expected. This is ok for my purposes, as the module I’m writing is for logging data sent from a source that doesn’t expect a response. The point of my module is to get raw POST data and dump it in a log, so destroying the POST variables doesn’t hurt anything in my case.

The Apache2::Request module is designed to parse and cache request data for the duration of a request. Of course, if you don’t instantiate it until a late phase when the POST has already been destroyed (as I was doing), it’s not very helpful. The module also happens to be a minor pain to install, unlike most perl modules I’ve had to deal with.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s