mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 01:08:32 +00:00
Add Sec-WebSocket-Key HTTP header
This commit is contained in:
parent
a39caefc8b
commit
e759b8e381
5 changed files with 17 additions and 19 deletions
|
@ -104,3 +104,4 @@ CF-Visitor, kHttpCfVisitor
|
||||||
CF-Connecting-IP, kHttpCfConnectingIp
|
CF-Connecting-IP, kHttpCfConnectingIp
|
||||||
CF-IPCountry, kHttpCfIpcountry
|
CF-IPCountry, kHttpCfIpcountry
|
||||||
CDN-Loop, kHttpCdnLoop
|
CDN-Loop, kHttpCdnLoop
|
||||||
|
Sec-WebSocket-Key, kHttpWebsocketKey
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
#line 12 "gethttpheader.gperf"
|
#line 12 "gethttpheader.gperf"
|
||||||
struct thatispacked HttpHeaderSlot { char *name; char code; };
|
struct thatispacked HttpHeaderSlot { char *name; char code; };
|
||||||
|
|
||||||
#define TOTAL_KEYWORDS 93
|
#define TOTAL_KEYWORDS 94
|
||||||
#define MIN_WORD_LENGTH 2
|
#define MIN_WORD_LENGTH 2
|
||||||
#define MAX_WORD_LENGTH 32
|
#define MAX_WORD_LENGTH 32
|
||||||
#define MIN_HASH_VALUE 3
|
#define MIN_HASH_VALUE 3
|
||||||
|
@ -387,7 +387,10 @@ LookupHttpHeader (register const char *str, register size_t len)
|
||||||
#line 87 "gethttpheader.gperf"
|
#line 87 "gethttpheader.gperf"
|
||||||
{"Strict-Transport-Security", kHttpStrictTransportSecurity},
|
{"Strict-Transport-Security", kHttpStrictTransportSecurity},
|
||||||
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
|
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
|
||||||
{""}, {""}, {""}, {""}, {""},
|
{""}, {""},
|
||||||
|
#line 107 "gethttpheader.gperf"
|
||||||
|
{"Sec-WebSocket-Key", kHttpWebsocketKey},
|
||||||
|
{""}, {""},
|
||||||
#line 22 "gethttpheader.gperf"
|
#line 22 "gethttpheader.gperf"
|
||||||
{"X-Forwarded-For", kHttpXForwardedFor},
|
{"X-Forwarded-For", kHttpXForwardedFor},
|
||||||
{""},
|
{""},
|
||||||
|
|
|
@ -206,6 +206,8 @@ const char *GetHttpHeaderName(int h) {
|
||||||
return "CDN-Loop";
|
return "CDN-Loop";
|
||||||
case kHttpSecChUaPlatform:
|
case kHttpSecChUaPlatform:
|
||||||
return "Sec-CH-UA-Platform";
|
return "Sec-CH-UA-Platform";
|
||||||
|
case kHttpWebsocketKey:
|
||||||
|
return "Sec-WebSocket-Key";
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,8 @@
|
||||||
#define kHttpCfIpcountry 90
|
#define kHttpCfIpcountry 90
|
||||||
#define kHttpSecChUaPlatform 91
|
#define kHttpSecChUaPlatform 91
|
||||||
#define kHttpCdnLoop 92
|
#define kHttpCdnLoop 92
|
||||||
#define kHttpHeadersMax 93
|
#define kHttpWebsocketKey 93
|
||||||
|
#define kHttpHeadersMax 94
|
||||||
|
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||||
COSMOPOLITAN_C_START_
|
COSMOPOLITAN_C_START_
|
||||||
|
|
|
@ -5066,23 +5066,14 @@ static int LuaUpgradeWS(lua_State *L) {
|
||||||
unsigned char hash[20];
|
unsigned char hash[20];
|
||||||
OnlyCallDuringRequest(L, "UpgradeWS");
|
OnlyCallDuringRequest(L, "UpgradeWS");
|
||||||
|
|
||||||
haskey = true;
|
if (!HasHeader(kHttpWebsocketKey))
|
||||||
for (i = 0; i < cpm.msg.xheaders.n; ++i) {
|
luaL_error(L, "No Sec-WebSocket-Key header");
|
||||||
if (SlicesEqualCase(
|
|
||||||
"Sec-WebSocket-Key", strlen("Sec-WebSocket-Key"),
|
|
||||||
inbuf.p + cpm.msg.xheaders.p[i].k.a,
|
|
||||||
cpm.msg.xheaders.p[i].k.b - cpm.msg.xheaders.p[i].k.a)) {
|
|
||||||
mbedtls_sha1_init(&ctx);
|
mbedtls_sha1_init(&ctx);
|
||||||
mbedtls_sha1_starts_ret(&ctx);
|
mbedtls_sha1_starts_ret(&ctx);
|
||||||
mbedtls_sha1_update_ret(
|
mbedtls_sha1_update_ret(&ctx, (unsigned char*)
|
||||||
&ctx, (unsigned char *)inbuf.p + cpm.msg.xheaders.p[i].v.a,
|
HeaderData(kHttpWebsocketKey),
|
||||||
cpm.msg.xheaders.p[i].v.b - cpm.msg.xheaders.p[i].v.a);
|
HeaderLength(kHttpWebsocketKey));
|
||||||
haskey = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!haskey) luaL_error(L, "No Sec-WebSocket-Key header");
|
|
||||||
|
|
||||||
p = SetStatus(101, "Switching Protocols");
|
p = SetStatus(101, "Switching Protocols");
|
||||||
while (p - hdrbuf.p + (20 + 21 + (20 + 28 + 4)) + 512 > hdrbuf.n) {
|
while (p - hdrbuf.p + (20 + 21 + (20 + 28 + 4)) + 512 > hdrbuf.n) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue