[Libwebsockets] http response headers

Andy Green andy at warmcat.com
Tue Feb 12 18:24:23 CET 2019



On February 12, 2019 9:18:53 AM PST, Kun Zhao <kunzhao77 at gmail.com> wrote:
>Andy,
>
>Thanks for your response. When calling lws_hdr_copy, I was using the
>size
>returned by lws_hdr_total_length and the string is empty. I figured out
>it
>has to be sz + 1 and it worked.

Yes it needs space for the NUL at the end.

-Andy

>case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: {
>      req->status = lws_http_client_http_response(wsi);
>      auto sz = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE);
>      char buf[1024];
>      lws_hdr_copy(wsi, buf, sz, WSI_TOKEN_HTTP_CONTENT_TYPE);
>          printf("???????? %d %s\n", sz,  buf);
>      break;
>    }
>
>Thanks,
>Kun
>
>
>On Tue, Feb 12, 2019 at 10:46 AM Andy Green <andy at warmcat.com> wrote:
>
>>
>>
>> On 11/02/2019 12:36, Kun Zhao wrote:
>> > Hi,
>> >
>> > For http client, how do I get response headers?
>>
>> At LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP you can get the server
>response
>> code with
>>
>> status = lws_http_client_http_response(wsi);
>>
>> and the server's response headers with the same apis used by
>server-side
>> to get the client request headers (they are parsed into the same ah
>> struct attached to the wsi either way), eg
>>
>>
>>
>https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-http.h#n344-353
>>
>>
>>
>https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-http.h#n368-383
>>
>> The list of known header indexes is here
>>
>>
>>
>https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-http.h#n214-305
>>
>> -Andy
>>
>> > Thanks,
>> > Kun
>> >
>> > _______________________________________________
>> > Libwebsockets mailing list
>> > Libwebsockets at ml.libwebsockets.org
>> > https://libwebsockets.org/mailman/listinfo/libwebsockets
>> >
>>


More information about the Libwebsockets mailing list