diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 82479bf3..6e31aec9 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -4307,6 +4307,8 @@ LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_finalize_write_http_header(struct lws *wsi, unsigned char *start, unsigned char **p, unsigned char *end); +#define LWS_ILLEGAL_HTTP_CONTENT_LEN ((lws_filepos_t)-1ll) + /** * lws_add_http_common_headers() - Helper preparing common http headers * @@ -4327,6 +4329,9 @@ lws_finalize_write_http_header(struct lws *wsi, unsigned char *start, * commonly needed. If it doesn't fit your case, or you want to add additional * headers just call the public apis directly yourself for what you want. * + * You can miss out the content length header by providing the constant + * LWS_ILLEGAL_HTTP_CONTENT_LEN for the content_len. + * * It does not call lws_finalize_http_header(), to allow you to add further * headers after calling this. You will need to call that yourself at the end. */ diff --git a/lib/roles/http/header.c b/lib/roles/http/header.c index 1e17279b..48beb745 100644 --- a/lib/roles/http/header.c +++ b/lib/roles/http/header.c @@ -143,11 +143,14 @@ lws_add_http_common_headers(struct lws *wsi, unsigned int code, { 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 (lws_add_http_header_content_length(wsi, content_len, p, end)) + + if (content_len != LWS_ILLEGAL_HTTP_CONTENT_LEN && + lws_add_http_header_content_length(wsi, content_len, p, end)) return 1; return 0;