[Libwebsockets] return values for callback_function

Andy Green andy at warmcat.com
Thu Nov 19 18:50:23 CET 2015

On 20 November 2015 01:29:37 GMT+08:00, "Charles Prévot" <prevot at cervval.com> wrote:
>Thanks for your answer.
>I have another small problem, in the case of a POST request, is there a
>to figure out the size of the body (other than relying on the
>Content-Length header) during the LWS_CALLBACK_HTTP call ?

No... that is what Content-Length is for.  That's a http thing not an lws thing.

>Because currently, if the body of the POST request is empty, I have no
>other callback called (no LWS_CALLBACK_HTTP_BODY_COMPLETION) so the
>waits for a body that never arrives and the client won't have a

Is there a Content-Length: 0 header coming in that case?


>2015-11-19 17:18 GMT+01:00 Andy Green <andy at warmcat.com>:
>> On 19 November 2015 21:55:01 GMT+08:00, "Charles Prévot" <
>> prevot at cervval.com> wrote:
>> >Hello,
>> >I have a quick question regarding the return values of callback. I
>> >that
>> >return 0 will continue and return -1 will close the connection, but
>> >test-server.c you also use return 1 (when building http headers). I
>> >failed
>> >to find any reference on that, is there a difference with returning
>> >?
>> For all the 'normal' callbacks the choice is just 0 = ok and nonzero
>> die.  Originally <0 was die which is why -1 was popular.
>> >Also, the family of http_header functions are not documented either
>> >I'm
>> >not sure of the meaning of a non-zero return from their side...
>> These were introduced to hide whether the underlying connection is
>> http2 or not.  Http2 deals with headers in a radically different,
>> binary-coded way, with multiple different options for header encoding
>> including huffman tables, and the codebook is dynamically updated
>> the kept-alive connection lifetime.  In particular you can't just
>> from headers to content in one packet with http2 as you could with
>> Anyway for both http1.x and http2 connections, they will return
>nonzero in
>> the case your requested header couldn't fit in the buffer you gave
>> -Andy
>> >Sincerely,

More information about the Libwebsockets mailing list