[Libwebsockets] http response headers

Kun Zhao kunzhao77 at gmail.com
Tue Feb 12 18:18:53 CET 2019


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.

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
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20190212/e3a9ad8d/attachment.html>


More information about the Libwebsockets mailing list