libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] SSI support


From: Christian Grothoff
Subject: Re: [libmicrohttpd] SSI support
Date: Wed, 29 Aug 2012 11:13:41 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4

Sorry, but looking at the code again I was clearly a bit wrong. If you look at 'try_ready_normal_body', the response's buffer will be used for the callback (after all, otherwise we would not need it). This is also necessary as the same response object might be shared between multiple connections, so here we should not use the per-connection buffer as we might be able to re-use the provided data.

So I think the correct answer would be that for *chunked* encoding, the per-connection buffer is used (see 'try_ready_chunked_body') whereas for 'normal' encoding, the per-response buffer is used. Note that the API also does not strictly guarantee this (and we might change this if we saw a reason to do so in the future). Chunked encoding is used with HTTP 1.1 if the content size is unknown (which would likely be the case with SSI), whereas 'normal' encoding would be used if you set "Connection: Close" explicitly or if the client connects with HTTP 1.0 or if the response size is not unknown.

Sorry for the confusion.

Happy hacking!

Christian

On 08/29/2012 09:17 AM, Martin Velek wrote:
Thank you for reply.

Thus I can save a little bit memory because if pool memory is always
used, the allocated space in function
MHD_create_response_from_callback() is never used.
See : line #231 in response.c
if (NULL == (response = malloc (sizeof (struct MHD_Response) + block_size)))
     return NULL;

E.g. block_size = 4 ->  only 4 bytes overhead.

Martin

On Sat, Aug 25, 2012 at 2:21 PM, Christian Grothoff
<address@hidden>  wrote:
Technically, whatever amount of memory is left in the memory pool
will be used for the buffer.  You can use the

MHD_OPTION_CONNECTION_MEMORY_LIMIT

to set the initial size of the memory pool (default: 32k).  Some
of that memory will go to storing the HTTP headers, the rest will be used as
the buffer for the response (if the response is generated using
the method you outlined).

Happy hacking!

Christian


On 08/25/2012 01:12 PM, Martin Velek wrote:
A supplementary question.

Where is decided which buffer will be used for data_generator
function? I have tried to set up block_size to 80 or 128 or 256 or
1024 and the data_generator function was always called with a buffer
from mem pool, size about 32KB.

M.V.
On Sat, Aug 25, 2012 at 10:37 AM, Martin Velek<address@hidden>
wrote:
Hello,

may I ask you, how to correctly implement SSI
(http://en.wikipedia.org/wiki/Server_Side_Includes) pages into
libmicrohttpd?

E.g. I have a page
#define PAGE "<html><head><title>libmicrohttpd demo</title>"\
               "</head><body>Temeprature:<!--#exec cgi="temperature"
--></body></html>"

The SSI parser knows that he should call const * char
temperature(void) when the string<!--#exec cgi="temperature" -->   is
found inside a html file. There is an issue, I cannot prepare the
whole reply in one buffer.

I have thought about using this function (taken from example)
   response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, xxx,
&data_generator, NULL, NULL);

And the data_generator, which contains SSI parser, will read from
given filename until<!--#exec cgi="temperature" -->   is found and
replace it by the output of const * char temperature(void). If no data
left, it will return MHD_CONTENT_READER_END_OF_STREAM.

Is it a fancy solution? Or if there is a better way how to handle it,
I will appreciate your help.

Thank you
Martin Velek





reply via email to

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