OK, so...
For those using the Perl Catalyst web framework in ways involving structured request bodies (e.g. API POSTs)...
$c->req->body is a string, unless Content-Type is application/x-www-form-urlencoded, text/xml, or multipart/form-data (or in fact application/json, which isn't in the docs), in which case it's a File::Temp (an overloaded file handle), and $c->req->body_data gets you the deserialised body.
For various reasons, largely to do with the idiosyncrasies of one particular module, I need to read the raw body data from the $c->req->body file handle to process a Stripe webhook payload. For various other reasons, as part of the API call logging, I need to call $c->req->body_data to get at the deserialised body in another module.
You may imagine my delight when adding the latter caused the former to fail.
An afternoon of bad language and extra debug eventually revealed that $c->req->body_data doesn't clean up after itself, and I have to seek( $c->req->body, 0, 0) before I can read any data from the body file handle.
If this is useful to anyone else, you have my sympathies.
Top comments (0)