[Libwebsockets] Tests server v-2.0 - POST doesn't work

Thomas Spitz thomas.spitz at hestia-france.com
Sun May 15 21:29:03 CEST 2016


Hello Andy,

I applied the changes from your patch but I didn't manage to make the POST
example work...

What I did is just the following changes from the CmakeLists.txt:

> option(LWS_WITH_LIBEV "Compile with support for libev" ON)#change
> option(LWS_WITH_LIBUV "Compile with support for libuv" ON)#change
> option(LWS_WITH_CGI "Include CGI (spawn process with network-connected
> stdin/out/err) APIs" ON)#change
> option(LWS_WITH_LWSWS "Libwebsockets Webserver" ON)#change
> option(LWS_WITH_PLUGINS "Support plugins for protocols and extensions"
> ON)#change

And I also moved the share folder in the bin folder in order to make
webserver files reachables

No reaction from Firefox, here the server logs:

> lwsts[17529]: LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: len 2
> lwsts[17529]:  0: 0x03
> lwsts[17529]:  1: 0xE9
> lwsts[17529]: CLOSING pss 0x239d2b0 ********
> lwsts[17529]: cache_len 94
> lwsts[17529]: lws_http_serve: /formtest
> lwsts[17529]: HTTP connect from localhost (127.0.0.1)
> lwsts[17529]: LWS_CALLBACK_HTTP_BODY: len 22
> lwsts[17529]: LWS_CALLBACK_HTTP_BODY_COMPLETION
> lwsts[17529]: 127.0.0.1 - - [15/May/2016:21:26:04 +0200] "POST /formtest
> http/1.1" 303 116 Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0)
> Gecko/20100101 Firefox/46.0
> lwsts[17529]: lws_http_serve: /postresults
> lwsts[17529]: HTTP connect from localhost (127.0.0.1)
> lwsts[17529]: ****** 23775b0 Sending new, pending truncated ...
> lwsts[17529]: 127.0.0.1 - - [15/May/2016:21:26:04 +0200] "GET /postresults
> http/1.1" 200 155 Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0)
> Gecko/20100101 Firefox/46.0

Error page "The localhost page isn’t working. localhost unexpectedly closed
the connection." from Chromium, here the server logs:

> lwsts[17529]: lws_http_serve: /formtest
> lwsts[17529]: HTTP connect from localhost (127.0.0.1)
> lwsts[17529]: LWS_CALLBACK_HTTP_BODY: len 22
> lwsts[17529]: LWS_CALLBACK_HTTP_BODY_COMPLETION
> lwsts[17529]: 127.0.0.1 - - [15/May/2016:21:27:12 +0200] "POST /formtest
> http/1.1" 303 116 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36
> (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108
> Safari/537.36
> lwsts[17529]: lws_http_serve: /postresults
> lwsts[17529]: HTTP connect from localhost (127.0.0.1)
> lwsts[17529]: ****** 23775b0 Sending new, pending truncated ...
> lwsts[17529]: 127.0.0.1 - - [15/May/2016:21:27:12 +0200] "GET /postresults
> http/1.1" 200 155 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36
> (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108
> Safari/537.36
> lwsts[17529]: LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: len 2
> lwsts[17529]:  0: 0x03
> lwsts[17529]:  1: 0xE9
> lwsts[17529]: CLOSING pss 0x239d280 ********
> lwsts[17529]: cache_len 94
> lwsts[17529]: lws_http_serve: /postresults
> lwsts[17529]: HTTP connect from localhost (127.0.0.1)
> lwsts[17529]: ****** 23775b0 Sending new, pending truncated ...
> lwsts[17529]: 127.0.0.1 - - [15/May/2016:21:27:12 +0200] "GET /postresults
> http/1.1" 200 133 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36
> (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108
> Safari/537.36



Best regards,
Thomas


2016-05-09 4:15 GMT+02:00 Andy Green <andy at warmcat.com>:

>
>
> On 05/08/2016 06:45 PM, Andy Green wrote:
>
>>
>>
>> On 05/08/2016 03:29 PM, Colin Adams wrote:
>>
>>> Trying out the v 2.0 test-server - everything works except in the POST
>>> tab, pressing on the "Send the form" button (apparently) does nothing.
>>>
>>> Might this be because of a compile-time #define needed?
>>>
>>
>> No... it's because the test-server-v2.0.c just uses a mount to do the
>> HTTP serving from inside the library, without any user code involved.
>>
>> That covers everything "normal" the test server does with HTTP, but the
>> POST needs to be handled by user code.
>>
>> I'll have a think about how to handle that nicely.
>>
>
> I pushed a patch on master
>
>
> https://github.com/warmcat/libwebsockets/commit/b24aaeb82261c480ab8e03baebda7aebedbc7d87
>
> that introduces a new mount type "callback://".
>
> Using that you can associate areas of your URL space with the callback of
> a named protocol.  In lwsws config JSON, it looks like this
>
>        {
>         "mountpoint": "/formtest",
>         "origin": "callback://protocol-post-demo"
>        }
>
> The patch also adds a new protocol plugin called "protocol-post-demo",
> whose callback handles the form post test in the test html.
>
> test-server-v2.0.c also gets an extra mount in code to use it.
>
> static const struct lws_http_mount mount_post = {
>         NULL,           /* linked-list pointer to next*/
>         "/formtest",            /* mountpoint in URL namespace on this
> vhost */
>         "protocol-post-demo",   /* handler */
>         NULL,   /* default filename if none given */
>         NULL,
>         0,
>         0,
>         0,
>         0,
>         0,
>         LWSMPRO_CALLBACK,       /* origin points to a callback */
>         9,                      /* strlen("/formtest"), ie length of the
> mountpoint */
> };
>
> With that, it's possible to cleanly map URL namespace to callbacks by
> name, and the test-server-v2.0 can do the POST part of the demo html nicely.
>
> -Andy
>
>
> -Andy
>>
>>
>>> _______________________________________________
>>> Libwebsockets mailing list
>>> Libwebsockets at ml.libwebsockets.org
>>> http://libwebsockets.org/mailman/listinfo/libwebsockets
>>>
>>> _______________________________________________
>> Libwebsockets mailing list
>> Libwebsockets at ml.libwebsockets.org
>> http://libwebsockets.org/mailman/listinfo/libwebsockets
>>
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://libwebsockets.org/mailman/listinfo/libwebsockets
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20160515/660bc4d2/attachment-0001.html>


More information about the Libwebsockets mailing list