Using "generic" POST parser in Apache2::Request - modperl

This is a discussion on Using "generic" POST parser in Apache2::Request - modperl ; Hi list, I'm trying to use libapreq2/Apache2::Request to access the POST body/payload under mod_perl2. According to the docs, one can potentially use APR::Request::Parser custom/generic to achieve this. What I'm trying to do is have Apache2::Request process POST payloads with "text/xml" ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Using "generic" POST parser in Apache2::Request

  1. Using "generic" POST parser in Apache2::Request

    Hi list,

    I'm trying to use libapreq2/Apache2::Request to access the POST
    body/payload under mod_perl2. According to the docs, one can
    potentially use APR::Request::Parser custom/generic to achieve this.
    What I'm trying to do is have Apache2::Request process POST payloads
    with "text/xml" as Content-Type.

    Does anybody have an example on how to do this?

    TIA,
    Srebrenko


  2. Re: Using "generic" POST parser in Apache2::Request

    On Wed, 10 Sep 2008 09:07:38 +0200
    Srebrenko wrote:

    > Hi list,
    >
    > I'm trying to use libapreq2/Apache2::Request to access the POST
    > body/payload under mod_perl2. According to the docs, one can
    > potentially use APR::Request::Parser custom/generic to achieve this.
    > What I'm trying to do is have Apache2::Request process POST payloads
    > with "text/xml" as Content-Type.
    >
    > Does anybody have an example on how to do this?
    >
    > TIA,
    > Srebrenko


    Hopefully someone will respond who has experience with libapreq2's hook
    API. The below example (libapreq2 not used) which decodes JSON (not
    XML) may provide some insight or a temporary solution.

    use Apache2::RequestRec ();
    use Apache2::RequestIO ();
    use Apache2::URI ();
    use Apache2::Const -compile => qw(M_POST);
    use JSON::XS qw(decode_json);

    if ($r->method_number() == Apache2::Const::M_POST) {
    if (my $ct = $r->header_in->{'Content-Type'}) {
    if ($ct =~ /\btext\/x-json\b/i) {
    if (my $len = $r->headers_in->{'Content-Length'}) {
    die 'read limit exceded'
    if $len > ((2**10) * 10); # 10K
    my $body = '';
    $r->read($body, $len);
    if ($ct =~ /\bx-www-form-urlencoded\b/i) {
    $body = Apache2::URI::unescape_url($body);
    }
    my $json = decode_json($body);
    }
    }
    }
    }


  3. Re: Using "generic" POST parser in Apache2::Request

    On Wed, Sep 10, 2008 at 12:39 PM, Ryan Gies wrote:

    > Hopefully someone will respond who has experience with libapreq2's hook
    > API. The below example (libapreq2 not used) which decodes JSON (not
    > XML) may provide some insight or a temporary solution.


    Thanks.

    I'm aware of the $r->read method. However, the reason why I'm not
    using that is that $r->read() makes the payload inaccessible to other
    filters. I need this, since the original request is proxied (using
    mod_proxy) to the backend systems after I take a peek. libapreq2
    already does this properly and that's the reason I was looking for
    that libapreq2 solution.

    Anybody else has a hint?


+ Reply to Thread