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

Andy Green andy at warmcat.com
Mon May 9 04:15:43 CEST 2016



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



More information about the Libwebsockets mailing list