libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] MHD_PostDataIterator issue


From: Christian Grothoff
Subject: Re: [libmicrohttpd] MHD_PostDataIterator issue
Date: Wed, 06 Feb 2013 21:55:17 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121122 Icedove/10.0.11

Well, it is working, just not the way your implementation may think it
should ;-).  Given that we cannot rely in even _having_ upload_data_size
(the browser may not have set content-length), the only sane choice for
giving such a value back from the post processor to the application is
within its destructor/destroy method --- before then, there are simply
always circumstances under which more data (an actual value!) might
still be given to the post processor.

So what you need to do is NOT call the 'MHD_destroy_post_processor'
function _after_ generating the response, but *before*.  You do this by
waiting until your response handler is called for a second time (for the
same request) with "*upload_data_size == 0".  Then *you* can be certain
that the upload is done (remember, the upload may be large and not be
given to MHD in a single network packet!), and thus you can call the PP
destroy method at that time.  After the PP has been destroyed (and only
then!), you can be sure that the callback you gave to the PP won't be
called with additional key-value pairs, and proceed to generate your
response.

I realize that calling the callback one last time in the PP destroy
method is, eh, 'unexpected', but it is the intended behavior and after
careful consideration on my part the only _correct_ solution that works
in all cases that I could find.

Happy hacking!

-Christian

On 02/06/2013 09:15 PM, Ovidiu Sas wrote:
> Hi,
> 
> After paying more attention to my logs, I realized that it's still not 
> working.
> I got tricked by the fact that the post iterator is run during it's 
> destruction.
> 
> In my application I see hat the MHD_post_process is called with
> upload_data_size=4 (which is 'arg=') but the post iterator callback
> function is never called from within the library.
> Then after the reply is sent and the MHD_destroy_post_processor is
> called, the post iterator callback is invoked (and here I got tricked
> previously thinking that it's working).
> 
> 
> Regards,
> Ovidiu Sas
> 
> 
> On Wed, Feb 6, 2013 at 11:08 AM, Ovidiu Sas <address@hidden> wrote:
>> Hmm ..., I checked the archive before posting but it seems that I
>> missed that report.
>> Anyway, I tested the new release and everything seems to be working fine.
>>
>> Thanks,
>> Ovidiu
>>
>> On Tue, Feb 5, 2013 at 7:53 PM, Christian Grothoff <address@hidden> wrote:
>>> Dear Ovidiu,
>>>
>>> The issue was discussed on this list a few days ago and fixed Feb 1st.
>>>
>>> I've now released GNU libextractor 0.9.25 with the fix.
>>>
>>>
>>> Happy hacking!
>>>
>>> Christian
>>>
>>> On 02/05/2013 10:31 PM, Ovidiu Sas wrote:
>>>> Hello all,
>>>>
>>>> I'm trying to use the library to handle simple POST requests.
>>>> During the implementation, I discovered an issue: if the post request
>>>> has one single key with no value, the MHD_PostDataIterator is not
>>>> invoked.
>>>> Here's an example of such post:
>>>> POST /mi/core/uptime HTTP/1.1.
>>>> Host: 192.168.2.60.
>>>> User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 
>>>> Firefox/18.0.
>>>> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8.
>>>> Accept-Language: en-US,en;q=0.5.
>>>> Accept-Encoding: gzip, deflate.
>>>> DNT: 1.
>>>> Referer: http://192.168.2.60/mi/core/uptime.
>>>> Connection: keep-alive.
>>>> Content-Type: application/x-www-form-urlencoded.
>>>> Content-Length: 4.
>>>> .
>>>> arg=
>>>>
>>>> The following post request is properly processed (MHD_PostDataIterator
>>>> is invoked):
>>>> POST /mi/core/uptime HTTP/1.1.
>>>> Host: 192.168.2.60.
>>>> User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 
>>>> Firefox/18.0.
>>>> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8.
>>>> Accept-Language: en-US,en;q=0.5.
>>>> Accept-Encoding: gzip, deflate.
>>>> DNT: 1.
>>>> Referer: http://192.168.2.60/mi/core/uptime.
>>>> Connection: keep-alive.
>>>> Content-Type: application/x-www-form-urlencoded.
>>>> Content-Length: 8.
>>>> .
>>>> arg=blah
>>>>
>>>>
>>>> I am using the library in single threaded mode (MHD_NO_FLAG) with select.
>>>> The version that I tested is 0.9.24.
>>>> The library is integrated into the opensips project and it is handling
>>>> GET requests.
>>>> http://opensips.svn.sourceforge.net/viewvc/opensips/trunk/modules/httpd/
>>>> I am looking to add POST request handling.
>>>>
>>>> I haven't check the libmicrohttpd source code yet ... just wanted to
>>>> know first if this is a known issue.
>>>>
>>>>
>>>> Regards,
>>>> Ovidiu Sas
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]