[Libwebsockets] work-around for lws 2.4.2

Andy Green andy at warmcat.com
Thu Oct 18 10:59:30 CEST 2018



On 18/10/18 09:31, Per Bothner wrote:
> I recently made some DomTerm changes to make use of 
> lws_add_http_common_header
> and lws_finalize_write_http_header.  Then I tried compiling using the 
> system
> version of lws on Fedora 28 - which is 2.4.2.  Oops.
> 
> I decided the cleanest solution was a "polyfill", by copying and 
> simplifying
> the respective implementations from lws master.  I hope this is ok.
> 
> #if LWS_LIBRARY_VERSION_NUMBER < (3*1000000+0*1000+0)
> // Copied and simplified from libwebsockets 3.x source.
> #ifndef LWS_ILLEGAL_HTTP_CONTENT_LEN
> #define LWS_ILLEGAL_HTTP_CONTENT_LEN ((lws_filepos_t)-1ll)
> #endif
> static int
> lws_add_http_common_headers(struct lws *wsi, unsigned int code,
>                              const char *content_type, lws_filepos_t 
> content_len,
>                              unsigned char **p, unsigned char *end)
> {
>      if (lws_add_http_header_status(wsi, code, p, end))
>          return 1;
>      if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE,
>                                       (unsigned char *)content_type,
>                                       (int)strlen(content_type), p, end))
>          return 1;
>      if (content_len != LWS_ILLEGAL_HTTP_CONTENT_LEN
>          && lws_add_http_header_content_length(wsi, content_len,
>                                                p, end))
>          return 1;
>      return 0;
> }
> static int
> lws_finalize_write_http_header(struct lws *wsi, unsigned char *start,
>                                 unsigned char **pp, unsigned char *end)
> {
>      unsigned char *p;
>      int len;
>      if (lws_finalize_http_header(wsi, pp, end))
>          return 1;
>      p = *pp;
>      len = (int)((char *)p - (char *)start);
>      if (lws_write(wsi, start, len, LWS_WRITE_HTTP_HEADERS) != len)
>          return 1;
>      return 0;
> }
> #endif
> 

It sounds like that's a good idea.  They're just helpers as you found 
which are made from already-public things.

-Andy


More information about the Libwebsockets mailing list