1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

lws_add_http_common_headers: provide WSI_TOKEN_HTTP_CONTENT_TYPE helper

This commit is contained in:
Andy Green 2018-04-20 07:12:31 +08:00
parent 3f683351b3
commit 658c752998
2 changed files with 9 additions and 1 deletions

View file

@ -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.
*/

View file

@ -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;