libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] chunked data mixed across multiple GETs


From: Evgeny Grin
Subject: Re: [libmicrohttpd] chunked data mixed across multiple GETs
Date: Sat, 19 Jun 2021 20:24:27 +0300
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

Hi Conor,

There are several ways how to implement it (send error reply early, suspend connection), but this is the worst way of fixing.

Blocking the second request is a hack, which is incompatible with what required from properly configured HTTP server.

The correct fix is ability to process several simultaneous requests.
It is very easy. Just do not use any global/static variables. You need to put all variables related to the response to the request-specific structure.

If you have any troubles with it, just publish simplified example of your callback function so we can discuss more precisely.

--
Wishes,
Evgeny

On 18.06.2021 22:59, Conor Lennon via libmicrohttpd wrote:
Thanks for that useful advice.

Yes - I think my issue is that I'm getting several requests.

Is there any way to configure libmicrohttpd to not accept a new HTTP request, 
or at least not call MHD_AccessHandlerCallback, until the previous
(chunked) response has completed?

Looking at the MHD_FLAGS enumeration,  nothing is jumping out at me.

On 18/06/2021 15:18, Evgeny Grin wrote:
Hi Conor,

If I've got you right, the question is not about large responses, but about 
simultaneous handling of several responses at the same time.

It is implemented very easily. When your application processes request, it 
should decide how you construct your response: for example, make
request A for database B or read picture X and convert it to to the format Z.
Then you need to put all parameters (the name of database and the request or 
picture location and final format) to the callback parameter
variable. See chunked_example.c, where 'callback_param' is always initialized 
with the same date. In practice it should be initialized with
data varied depending on the request.

If you are reusing the same response (struct MHD_Response object) for several 
requests, you must ensure that your callback generates response
data for response position provided as callback parameter. In this case it 
doesn't matter which request is served, the data is determined by
response object and position.

Alternatively, if you are using unique responses for each request (as it was 
done in the example), you can put (update) number of last line
sent to the client into your callback parameter and start your next chunk from 
the next line.


Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

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