Question

I am developing a module for apache that performs some authentication before passing requests off to the backend. Some of this authentication at times requires parsing form data. The problem is that ap_parse_form_data appears to exhaust the request body, so that by the time it passes my module and gets to the ProxyPass directive which funnels it off to the backend, the request body is gone and the backend thinks there is no form data supplied.

Is there any way to use ap_parse_form_data in such a way that it keeps the request body intact?

Was it helpful?

Solution

For the record, I ended up not figuring out how to get ap_parse_form_data to not discard the request body. I was able to achieve the same effect by manually adding back a request body like so:

apr_bucket_brigade *new_brigade = apr_brigade_create(req->pool, req->connection->bucket_alloc);
apr_bucket *bucket = apr_bucket_transient_create(reencoded_form_data,
    strlen(reencoded_form_data), req->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(new_brigade, bucket);    
req->kept_body = new_brigade;

This is not ideal since it does not deal with the discarding of the request body side-effect if ap_parse_form_data is called on a request body that does not actually contain form data. But it works enough for my purposes...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top