[Libwebsockets] libwebsockets based http CLIENT

Andy Green andy at warmcat.com
Mon Apr 18 09:25:08 CEST 2016



On 04/18/2016 03:19 PM, Zlotin, Lev wrote:
> I tried master too; It has the same issues.

As I say before master, client http is not supported.  In master, it's 
supported for another purpose (proxying).  I'll extend it to work generally.

> I do not know, what is causing the redirect; I use the simplest server( mongoose 3.7 ) with index.htm with the only line "hello, word."
> But log shows that redirect

The only way to get the redirect is from a 3xx server response

	if (n == 301 || n == 302 || n == 303 || n == 307 || n == 308) {
		p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_LOCATION);
		if (!p)
			goto bail3;

		if (lws_parse_uri(p, &prot, &ads, &port, &path))
			goto bail3;

		if (!strcmp(prot, "wss://") || !strcmp(prot, "https://"))
			ssl = 1;

		if (lws_client_reset(wsi, ssl, ads, port, path, ads)) {
			lwsl_err("Redirect failed\n");
			goto bail3;
		}

Maybe eyeball what happens on the wire with tcpdump, you should see a 
3xx response from the server unless I completely missed the point.

-Andy

> See the log:
> [2016/03/18 10:17:23:9687] NOTICE: using http mode (non-ws)
> [2016/03/18 10:17:23:9687] NOTICE: http: connecting
> [2016/03/18 10:17:23:9687] INFO: lws_ensure_user_space: 000000AC004CD690 protocol 00007FF7B8FF1290
> [2016/03/18 10:17:23:9687] INFO: lws_ensure_user_space: 000000AC004CD690 protocol pss 0, user_space=0
> [2016/03/18 10:17:23:9687] INFO: lws_header_table_attach: wsi 000000AC004CD690: ah 0000000000000000 (tsi 0)
> [2016/03/18 10:17:23:9687] INFO: lws_header_table_attach: wsi 000000AC004CD690: ah 000000AC004106C0: count 1 (on exit)
> callback_http: reason 35
> callback_http: reason 32
> callback_http: reason 36
> callback_http: reason 29
> callback_http: reason 35
> callback_http: reason 34
> callback_http: reason 36
> callback_http: reason 31
> callback_http: reason 27
> callback_http: reason 35
> callback_http: reason 34
> callback_http: reason 36
> callback_http: reason 24
> callback_http: reason 31
> [2016/03/18 10:17:23:9977] NOTICE: redirect ads='', port=0, path='/'
> callback_http: reason 35
> [2016/03/18 10:17:23:9977] INFO: remove_wsi_socket_from_fds: wsi=000000AC004CD690, sock=316, fds pos=0, end guy pos=1, e
> ndfd=0
> callback_http: reason 33
> callback_http: reason 36
> callback_http: reason 35
> callback_http: reason 32
> callback_http: reason 36
> callback_http: reason 29
> [2016/03/18 10:17:24:0468] INFO: lws_close_free_wsi: shutting down connection: 000000AC004CD690 (sock 348)
>
> Thanks,
> Lev Zlotin
> Lev.zlotin at intel.com
> +972-4-8656740
> +972-53-5207679
>
> -----Original Message-----
> From: Andy Green [mailto:andy at warmcat.com]
> Sent: Monday, April 18, 2016 10:01
> To: Zlotin, Lev <lev.zlotin at intel.com>; libwebsockets at ml.libwebsockets.org
> Subject: Re: [Libwebsockets] libwebsockets based http CLIENT
>
>
>
> On 04/18/2016 02:40 PM, Zlotin, Lev wrote:
>> Hi,
>>
>> I'm trying to implement the http client( currently - simple prototype
>> ) based on libwebsockets; I met some issues:
>>
>> 1.Lack of any documentation/tutorial/etc. Can you point me to any
>> documentation on development of http client?
>
> Until the current stuff in master, the client part of lws assumes that you are wanting a websocket connection, not an http one.  It has always handled server http responses but only in order to get itself upgraded to ws (it is libwebsockets after all...)
>
> However on master, there's an optional method member of lws_client_connect_info you can set to "GET" to have it work just at http and not ws.  This info is in the libwebsockets.h on master.
>
>    * @method:	if non-NULL, do this http method instead of ws[s] upgrade.
>    *		use "GET" to be a simple http client connection
>
> The test client on master branch supports connecting over http[s] like this
>
> libwebsockets-test-client http://example.com
>
> however this isn't complete yet, master uses it for http proxying not for http client.
>
>> 2.I built something base on echo client in examples. However, I'm
>> getting crash in a library, which is related to "redirect": during
>> redirect function "lws_client_reset" is called, which writes NULL to
>> wsi->protocol. Wsi->protocol is executed after without any check for NULL.
>
> Sorry what exactly causes the 'redirect'... the client is connecting to a server that requests a redirect?
>
>   From what you're saying you should look at master branch test-client.
>
> I'll complete the support in test-client shortly and then basing off that should work well.
>
> -Andy
>
>
>> Although after fixing of this issue, nothing is working
>>
>> Can you please point me to any tutorial/documentation/sample
>> implementation for http/https client with libwebsockets?
>>
>> *Thanks,*
>>
>> *Lev Zlotin*
>>
>> *Lev.zlotin at intel.com*
>>
>> *+972-4-8656740*
>>
>> *+972-53-5207679*
>>
>> ---------------------------------------------------------------------
>> Intel Israel (74) Limited
>>
>> This e-mail and any attachments may contain confidential material for
>> the sole use of the intended recipient(s). Any review or distribution
>> by others is strictly prohibited. If you are not the intended
>> recipient, please contact the sender and delete all copies.
>>
>>
>>
>> _______________________________________________
>> Libwebsockets mailing list
>> Libwebsockets at ml.libwebsockets.org
>> http://libwebsockets.org/mailman/listinfo/libwebsockets
>>
> ---------------------------------------------------------------------
> Intel Israel (74) Limited
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
>



More information about the Libwebsockets mailing list