You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Steve Kemp <st...@steve.org.uk> on 2006/11/06 17:15:28 UTC
Re: Reading POST request without destroying it?
A while back I asked for help with reading POST data in a module,
such that it would still be available for use by CGI processes etc.
I thought I had a solution using brigades and buckets, but it
seems like I'm still missing the obvious as my data is still removed
by the time mod_cgi/mod_php is invoked.
I've included the code I'm using below, if there is anything
immediately visible I'd appreciate pointers ..
Steve
--
http://www.steve.org.uk/
tatic const char * mod_ifier_parse_read_post_payload(request_rec *r, const char **rbuf)
{
apr_bucket_brigade *bb;
int seen_eos = 0;
apr_status_t rv;
apr_uri_t *uri = &r->parsed_uri;
uri->query = "";
bb = apr_brigade_create(r->pool,r->connection->bucket_alloc);
do
{
apr_bucket *bucket;
rv = ap_get_brigade(r->input_filters,bb,AP_MODE_READBYTES,APR_BLOCK_READ,HUGE_STRING_LEN);
if (rv != APR_SUCCESS)
{
return NULL;
}
while (!APR_BRIGADE_EMPTY(bb))
{
const char *data;
apr_size_t len;
bucket = APR_BRIGADE_FIRST(bb);
if (APR_BUCKET_IS_EOS(bucket))
{
seen_eos = 1;
break;
}
if (APR_BUCKET_IS_FLUSH(bucket))
{
continue;
}
apr_bucket_read(bucket,&data,&len,APR_BLOCK_READ);
uri->query = apr_pstrcat(r->pool,uri->query,data,NULL);
apr_bucket_delete(bucket);
}
apr_brigade_cleanup(bb);
} while (!seen_eos);
return( apr_pstrdup( r->pool, uri->query ) );
}