Saw a websocket message go across the wire with this.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4693 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2023-12-24 21:39:51 +00:00
parent 1621f1753a
commit 606e82d718
2 changed files with 22 additions and 11 deletions

View File

@ -124,17 +124,18 @@ static void _httpd_callback(tf_http_request_t* request)
SHA1(key_magic, size, digest);
char key[41] = { 0 };
tf_base64_encode(digest, sizeof(digest), key, sizeof(key));
tf_printf("ACCEPT %s\n", key);
enum { k_headers_count = 4 };
const char* headers[k_headers_count * 2] =
{
"Upgrade", "websocket",
"Connection", "upgrade",
"Connection", "Upgrade",
"Sec-WebSocket-Accept", key,
"Sec-WebSocket-Version", "13",
};
tf_http_respond(request, 101, headers, k_headers_count, NULL, 0);
bool send_version =
!tf_http_request_get_header(request, "sec-websocket-version") ||
strcmp(tf_http_request_get_header(request, "sec-websocket-version"), "13") != 0;
tf_http_respond(request, 101, headers, send_version ? k_headers_count : (k_headers_count - 1), NULL, 0);
return;
}
}