libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] Difference in handling of MHD_AccessHandlerCallback


From: Christian Grothoff
Subject: Re: [libmicrohttpd] Difference in handling of MHD_AccessHandlerCallback between 0.4.4 and 0.4.6
Date: Wed, 31 Mar 2010 23:43:01 +0200
User-agent: KMail/1.12.4 (Linux/2.6.31-14-generic; KDE/4.3.5; i686; ; )

On Saturday 27 March 2010 04:35:29 pm John Lee wrote:
> Hello there,
> I've noticed that there is a difference between MHD_AccessHandlerCallback
> usage between 0.4.4 and 0.4.6. For example, sending a JSON object post
> payload of about ~450 bytes, *not* multi-part, *no* chunking.
> 
> 1) 0.4.4
> MHD_AccessHandlerCallback Call #1:
> upload_data points to the entire allocated POST payload
> *upload_data_size = 453
> Create post processor and initialise state for the connection including the
> size of payload
> 
> MHD_AccessHandlerCallback Call #2:
> upload_data points to the entire allocated POST payload
> *upload_data_size = 453
> Call MHD_post_process to process POST data.
> 
> MHD_AccessHandlerCallback Call #3:
> upload_data points to the entire allocated POST payload
> *upload_data_size = 0 (i.e. finished processing the POST payload)
> The MHD_PostDataIterator function was never called, presumably because MHD
> could handle in one chunk.
> I pass the upload_data and stored size onto other network applications
> before replying to client.
> The upload data memory is allocated for the entire duration of the HTTP
> request / response transaction.

Well, you should have during #3 called "MHD_destroy_post_processor" to 
indicate to the PP that this was the end of the upload.  At this point, your 
PostDataIterator would have been triggered.  Other than that, what you 
describe sounds just fine.  Note that in #3, if "*upload_data_size=0" MHD 
makes no guarantees about what "upload_data" points to.  You should not use it 
anymore.

> 2) 0.4.6
> MHD_AccessHandlerCallback Call #1:
> upload_data points to the entire allocated POST payload
> *upload_data_size = 453
> Create post processor and initialise state for the connection including the
> size of payload
> 
> ...
> 
> MHD_AccessHandlerCallback Call #3:
> upload_data points to NULL
> *upload_data_size = 0 (i.e. finished processing the POST payload)
> 
> The upload data memory is no longer allocated? Is it up to the user to
> allocate memory for the POST payload?

Only "*upload_data_size" of "upload_data" are valid, so if that value is 0, 
you should not use "upload_data".  MHD 0.4.6 is only "nicer" to you in that it 
gives you NULL to make this clear (even though I don't recall changing 
anything here, either behavior is technically correct as far as I am 
concerned).  

The main point here is that you need to call the MHD_destroy_post_processor 
which will at that point cause the remaining "unprocessed" data given to the 
PP previously to be processed (causing MHD PP to call your iterator before 
returning from MHD_destroy_post_processor).

Happy hacking!

Christian




reply via email to

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