httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pranesh Vadhirajan" <vadhira...@teralogics.com>
Subject RE: Reading content of requests entering Apache
Date Tue, 10 Jan 2012 18:55:43 GMT
Hello All,
I realized that the reason that the function doesn't do what I want is that
I am using the ap_setup_client_block() call in the function, which reads
client block content for POST or PUT requests.  

I am attempting to read the content on a GET request.  Is there an analogous
function I can use? Or a simple API?

Thanks,
Pranesh


-----Original Message-----
From: Pranesh Vadhirajan [mailto:vadhirajan@teralogics.com] 
Sent: Tuesday, January 10, 2012 10:55 AM
To: modules-dev@httpd.apache.org
Subject: RE: Reading content of requests entering Apache

Hello,
     When I call the following function from the handler function in my
module, I expect to see the buffer contain the packet contents when I print
the buffer.  However I see a null buffer on every request.  Is there a
certain order that I have to execute my modules?  I have tried to execute it
in FIRST, MIDDLE and LAST positions.  I have also tried to execute my module
directly after mod_proxy.  Is there some other issue with this function?  

I have tried to look at the mod_deflate module as an example, but I am not
able to understand it in order to apply its principles here.  So, if it
would be possible to fix the following function to make it work, that would
be greatly appreciated.  

static int util_read(request_rec *r, const char** rbuf)
{
   int rc;
    if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)) != OK) {
       return rc;
   }
    if (ap_should_client_block(r)) {
       char argsbuffer[HUGE_STRING_LEN];
      int rsize, len_read, rpos=0;
      long length = r->remaining;
      *rbuf = apr_pcalloc(r->pool, length + 1);
       
       while ((len_read =
               ap_get_client_block(r, argsbuffer, sizeof(argsbuffer))) > 0)
{
          
          if ((rpos + len_read) > length) {
              rsize = length - rpos;
          }
          else {
              rsize = len_read;
          }
          memcpy((char*)*rbuf + rpos, argsbuffer, rsize);
          rpos += rsize;
      }
       
    }
    fprintf(stderr,"Buffer: %s\n",*rbuf);
   return rc;
}

static int my_handler(request_rec* r) {
        char msg_content[1024] = {'\0'};
        util_read(r,(const char**)&msg_content);
        return DECLINED;
}


Thanks,
Pranesh


-----Original Message-----
From: Nick Kew [mailto:niq@apache.org] 
Sent: Monday, January 09, 2012 10:52 AM
To: modules-dev@httpd.apache.org
Subject: Re: Reading content of requests entering Apache

On Mon, 9 Jan 2012 10:33:53 -0500
"Pranesh Vadhirajan" <vadhirajan@teralogics.com> wrote:

> Hello All,
> 
>      I would like to know how to be able to read the content of the
request
> that Apache receives.

What you describe is called an Input Filter.  There are examples in
the the standard apache distro: for example, mod_deflate and mod_sed
offer input filters.  mod_security and mod_ironbee are third-party
examples.

I could also recommend the book: see http://www.apachetutor.org/


-- 
Nick Kew

Mime
View raw message