[Libwebsockets] POST client

Andy Green andy at warmcat.com
Fri Mar 6 14:07:12 CET 2020

On 3/6/20 12:29 PM, Karl Vogel wrote:
> I'm trying to issue a POST with a msgpack payload to fluent. However I'm 
> always getting back an error in the LWS_CALLBACK_CLIENT_CONNECTION_ERROR 
> callback with error message "HS: URI missing", while the post is 
> correctly being received by fluent and it's replying with an HTTP-200.

So you are succeeding to "issue a POST...".

> The LWS_CALLBACK_CLIENT_HTTP_WRITEABLE just does an lws_write of the 
> msgpack payload, with LWS_WRITE_HTTP_FINAL set. I am setting the 
> Content-Type and Content-Length headers in the handshake callback.

As you mentioned above, your peer is getting it OK, so that part should 
be OK.

> The callback sequence is:
>  >>>>>>>>>>>>>> LWS_CALLBACK_WSI_CREATE
> setting headers
>   writing payload 55 bytes

HS: URI missing means there's a problem with lws interpreting the http 
response from the peer.  Specifically, lws wants to see

"http/1.1 " or "http/1.0 "

in what comes back; if it was an h2 connection it'd insist to see 
":status" and give a different error if it was missing.

You can crank up the lws logging by cmake .. -DCMAKE_BUILD_TYPE=DEBUG 
and give debug filter like 1151, it will show you a char-by-char attempt 
to parse what your peer sent back.

>   ** FAILED (-1) **
> I had a look at the minimal post example, but that one is using 
> multipart body parts, while my code is just posting the raw msgpack 
> message. Is this supported? How should the writeable callback end the post?

I don't think it's relevent if the peer actually got your POST content.

> Using the master branch.

Make sure you're using today's current master HEAD, it's 
1289b0a0ef6fde60cb2d765c380a67167ca522f2 at the moment, or v4.0-stable 
that's out today.  Under some conditions http headers were broken a few 
days ago briefly on master due to changes allowing chopping them down if 
h2, ws, or "uncommon headers" are disabled for build in cmake, for very 
small footprint case.


> Karl
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets

More information about the Libwebsockets mailing list