mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-23 00:00:06 +01:00
h2: use vhost headers with tolower adaptation
h2 was not applying vhost headers, make it do so. Also adapt any header names to lower-case as required by h2.
This commit is contained in:
parent
1a44e20b6a
commit
446c790525
3 changed files with 36 additions and 28 deletions
|
@ -1356,8 +1356,12 @@ int lws_add_http2_header_by_name(struct lws *wsi, const unsigned char *name,
|
|||
*((*p)++) = 0 | lws_h2_num_start(7, len); /* non-HUF */
|
||||
if (lws_h2_num(7, len, p, end))
|
||||
return 1;
|
||||
memcpy(*p, name, len);
|
||||
*p += len;
|
||||
|
||||
/* upper-case header names are verboten in h2, but OK on h1, so
|
||||
* they're not illegal per se. Silently convert them for h2... */
|
||||
|
||||
while(len--)
|
||||
*((*p)++) = tolower((int)*name++);
|
||||
|
||||
*((*p)++) = 0 | lws_h2_num_start(7, length); /* non-HUF */
|
||||
if (lws_h2_num(7, length, p, end))
|
||||
|
@ -1366,8 +1370,6 @@ int lws_add_http2_header_by_name(struct lws *wsi, const unsigned char *name,
|
|||
memcpy(*p, value, length);
|
||||
*p += length;
|
||||
|
||||
//lwsl_hexdump(op, *p -op);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -212,34 +212,40 @@ lws_add_http_header_status(struct lws *wsi, unsigned int _code,
|
|||
#endif
|
||||
|
||||
#ifdef LWS_WITH_HTTP2
|
||||
if (lwsi_role_h2(wsi) || lwsi_role_h2_ENCAPSULATION(wsi))
|
||||
return lws_add_http2_header_status(wsi, code, p, end);
|
||||
if (lwsi_role_h2(wsi) || lwsi_role_h2_ENCAPSULATION(wsi)) {
|
||||
n = lws_add_http2_header_status(wsi, code, p, end);
|
||||
if (n)
|
||||
return n;
|
||||
} else
|
||||
#endif
|
||||
if (code >= 400 && code < (400 + LWS_ARRAY_SIZE(err400)))
|
||||
description = err400[code - 400];
|
||||
if (code >= 500 && code < (500 + LWS_ARRAY_SIZE(err500)))
|
||||
description = err500[code - 500];
|
||||
{
|
||||
if (code >= 400 && code < (400 + LWS_ARRAY_SIZE(err400)))
|
||||
description = err400[code - 400];
|
||||
if (code >= 500 && code < (500 + LWS_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 (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 < LWS_ARRAY_SIZE(hver))
|
||||
p1 = hver[wsi->http.request_version];
|
||||
else
|
||||
p1 = hver[0];
|
||||
if (wsi->http.request_version < LWS_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;
|
||||
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,
|
||||
|
|
|
@ -423,7 +423,7 @@ lejp_vhosts_cb(struct lejp_ctx *ctx, char reason)
|
|||
headers->next = a->info->headers;
|
||||
a->info->headers = headers;
|
||||
headers->name = a->p;
|
||||
// lwsl_notice(" adding header %s=%s\n", a->p, ctx->buf);
|
||||
lwsl_notice(" adding header %s=%s\n", a->p, ctx->buf);
|
||||
a->p += n - 1;
|
||||
*(a->p++) = ':';
|
||||
if (a->p < a->end)
|
||||
|
|
Loading…
Add table
Reference in a new issue