int lws_add_http_header_status(struct lws *wsi, unsigned int code, unsigned char **p, unsigned char *end) { unsigned char code_and_desc[60]; const char *description = "", *p1; int n; static const char * const hver[] = { "HTTP/1.0", "HTTP/1.1", "HTTP/2" }; #ifdef LWS_WITH_ACCESS_LOG wsi->access_log.response = code; #endif #ifdef LWS_USE_HTTP2 if (wsi->mode == LWSCM_HTTP2_SERVING) return lws_add_http2_header_status(wsi, code, p, end); #endif if (code >= 400 && code < (400 + ARRAY_SIZE(err400))) description = err400[code - 400]; if (code >= 500 && code < (500 + ARRAY_SIZE(err500))) description = err500[code - 500]; if (code == 200) description = "OK"; if (code >= 300 && code < 400) description = "Redirect"; if (wsi->u.http.request_version < ARRAY_SIZE(hver)) p1 = hver[wsi->u.http.request_version]; else p1 = hver[0]; n = sprintf((char *)code_and_desc, "%s %u %s", p1, code, description); if (lws_add_http_header_by_name(wsi, NULL, code_and_desc, n, p, end)) return 1; if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER, (unsigned char *) wsi->context->server_string, wsi->context->server_string_len, p, end)) return 1; if (wsi->vhost->options & LWS_SERVER_OPTION_STS) if (lws_add_http_header_by_name(wsi, (unsigned char *) "Strict-Transport-Security:", (unsigned char *)"max-age=15768000 ; " "includeSubDomains", 36, p, end)) return 1; return 0; }
int lws_add_http_header_status(struct lws *wsi, unsigned int code, unsigned char **p, unsigned char *end) { unsigned char code_and_desc[60]; const char *description = ""; int n; #ifdef LWS_USE_HTTP2 if (wsi->mode == LWSCM_HTTP2_SERVING) return lws_add_http2_header_status(wsi, code, p, end); #endif if (code >= 400 && code < (400 + ARRAY_SIZE(err400))) description = err400[code - 400]; if (code >= 500 && code < (500 + ARRAY_SIZE(err500))) description = err500[code - 500]; n = sprintf((char *)code_and_desc, "HTTP/1.0 %u %s", code, description); return lws_add_http_header_by_name(wsi, NULL, code_and_desc, n, p, end); }
int lws_add_http_header_status(struct lws *wsi, unsigned int _code, unsigned char **p, unsigned char *end) { STORE_IN_ROM static const char * const hver[] = { "HTTP/1.0", "HTTP/1.1", "HTTP/2" }; const struct lws_protocol_vhost_options *headers; unsigned int code = _code & LWSAHH_CODE_MASK; const char *description = "", *p1; unsigned char code_and_desc[60]; int n; #ifdef LWS_WITH_ACCESS_LOG wsi->access_log.response = code; #endif #ifdef LWS_WITH_HTTP2 if (wsi->mode == LWSCM_HTTP2_SERVING) return lws_add_http2_header_status(wsi, code, p, end); #endif if (code >= 400 && code < (400 + ARRAY_SIZE(err400))) description = err400[code - 400]; if (code >= 500 && code < (500 + ARRAY_SIZE(err500))) description = err500[code - 500]; if (code == 100) description = "Continue"; if (code == 200) description = "OK"; if (code == 304) description = "Not Modified"; else if (code >= 300 && code < 400) description = "Redirect"; if (wsi->http.request_version < ARRAY_SIZE(hver)) p1 = hver[wsi->http.request_version]; else p1 = hver[0]; n = sprintf((char *)code_and_desc, "%s %u %s", p1, code, description); if (lws_add_http_header_by_name(wsi, NULL, code_and_desc, n, p, end)) return 1; headers = wsi->vhost->headers; while (headers) { if (lws_add_http_header_by_name(wsi, (const unsigned char *)headers->name, (unsigned char *)headers->value, (int)strlen(headers->value), p, end)) return 1; headers = headers->next; } if (wsi->context->server_string && !(_code & LWSAHH_FLAG_NO_SERVER_NAME)) if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER, (unsigned char *)wsi->context->server_string, wsi->context->server_string_len, p, end)) return 1; if (wsi->vhost->options & LWS_SERVER_OPTION_STS) if (lws_add_http_header_by_name(wsi, (unsigned char *) "Strict-Transport-Security:", (unsigned char *)"max-age=15768000 ; " "includeSubDomains", 36, p, end)) return 1; return 0; }