You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Greg Stein <gs...@lyra.org> on 1999/11/19 01:44:20 UTC

ap_discard_request_body() problems

It seems that ap_discard_request_body() could really bung things up if it
happens to be called twice. Each time it is called, it resets how much
data needs to be read from the client. Then it proceeds to read that
amount.

Okay, fine: make sure to call it only once.

Well... that is quite difficult. The comments in the source encourage
placing it at the top of your handler if you don't have a body. However,
if you return something other than DONE from your handle (e.g.
HTTP_NOT_FOUND), then ap_die() will *also* call it.

Oh, ick. Just thought of a related problem. Let's say that I consume the
request body, parse it, and return an error. Oops.
ap_discard_request_body() will get called and tried to read that input
again.

I think the proper resolution is to allow ap_discard_request_body() to do
nothing if all input has been read. However, I'm not clear on what
variables in the request record are used to determine "okay, we've got it
all."

Thoughts?

thx,
-g

-- 
Greg Stein, http://www.lyra.org/


Re: ap_discard_request_body() problems

Posted by Greg Stein <gs...@lyra.org>.
Oh... never mind. I found how it protects against a double-call.
ap_get_client_block() increments r->read_length. discard() checks to
ensure that is zero before doing anything. i.e. if a handle starts reading
any portion of the body, then it better read the whole thing.

thx,
-g

On Thu, 18 Nov 1999, Greg Stein wrote:

> It seems that ap_discard_request_body() could really bung things up if it
> happens to be called twice. Each time it is called, it resets how much
> data needs to be read from the client. Then it proceeds to read that
> amount.
> 
> Okay, fine: make sure to call it only once.
> 
> Well... that is quite difficult. The comments in the source encourage
> placing it at the top of your handler if you don't have a body. However,
> if you return something other than DONE from your handle (e.g.
> HTTP_NOT_FOUND), then ap_die() will *also* call it.
> 
> Oh, ick. Just thought of a related problem. Let's say that I consume the
> request body, parse it, and return an error. Oops.
> ap_discard_request_body() will get called and tried to read that input
> again.
> 
> I think the proper resolution is to allow ap_discard_request_body() to do
> nothing if all input has been read. However, I'm not clear on what
> variables in the request record are used to determine "okay, we've got it
> all."
> 
> Thoughts?
> 
> thx,
> -g
> 
> -- 
> Greg Stein, http://www.lyra.org/
> 

-- 
Greg Stein, http://www.lyra.org/