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

make origin optional on client

Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
Andy Green 2011-02-26 10:22:49 +00:00
parent 6901cb3b4e
commit 08d33926eb
2 changed files with 24 additions and 16 deletions

View file

@ -78,10 +78,13 @@ libwebsocket_client_connect(struct libwebsocket_context *this,
if (wsi->c_host == NULL)
goto oom1;
strcpy(wsi->c_host, host);
wsi->c_origin = malloc(strlen(origin) + 1);
if (wsi->c_origin == NULL)
goto oom2;
strcpy(wsi->c_origin, origin);
if (origin) {
wsi->c_origin = malloc(strlen(origin) + 1);
strcpy(wsi->c_origin, origin);
if (wsi->c_origin == NULL)
goto oom2;
} else
wsi->c_origin = NULL;
if (protocol) {
wsi->c_protocol = malloc(strlen(protocol) + 1);
if (wsi->c_protocol == NULL)
@ -216,7 +219,8 @@ oom4:
free(wsi->c_protocol);
oom3:
free(wsi->c_origin);
if (wsi->c_origin)
free(wsi->c_origin);
oom2:
free(wsi->c_host);

View file

@ -749,7 +749,8 @@ libwebsocket_service_fd(struct libwebsocket_context *this,
SYSTEM_RANDOM_FILEPATH);
free(wsi->c_path);
free(wsi->c_host);
free(wsi->c_origin);
if (wsi->c_origin)
free(wsi->c_origin);
if (wsi->c_protocol)
free(wsi->c_protocol);
libwebsocket_close_and_free_session(this, wsi);
@ -772,26 +773,29 @@ libwebsocket_service_fd(struct libwebsocket_context *this,
* Sec-WebSocket-Version: 4
*/
p += sprintf(p, "GET %s HTTP/1.1\x0d\x0a", wsi->c_path);
p += sprintf(p, "Host: %s\x0d\x0a", wsi->c_host);
p += sprintf(p, "Upgrade: websocket\x0d\x0a");
p += sprintf(p, "Connection: Upgrade\x0d\x0a"
p += sprintf(p, "GET %s HTTP/1.1\x0d\x0a", wsi->c_path);
p += sprintf(p, "Host: %s\x0d\x0a", wsi->c_host);
p += sprintf(p, "Upgrade: websocket\x0d\x0a");
p += sprintf(p, "Connection: Upgrade\x0d\x0a"
"Sec-WebSocket-Key: ");
strcpy(p, wsi->key_b64);
p += strlen(wsi->key_b64);
p += sprintf(p, "\x0d\x0aSec-WebSocket-Origin: %s\x0d\x0a",
strcpy(p, wsi->key_b64);
p += strlen(wsi->key_b64);
p += sprintf(p, "\x0d\x0a");
if (wsi->c_origin)
p += sprintf(p, "Sec-WebSocket-Origin: %s\x0d\x0a",
wsi->c_origin);
if (wsi->c_protocol != NULL)
if (wsi->c_protocol)
p += sprintf(p, "Sec-WebSocket-Protocol: %s\x0d\x0a",
wsi->c_protocol);
p += sprintf(p, "Sec-WebSocket-Version: %d\x0d\x0a\x0d\x0a",
p += sprintf(p, "Sec-WebSocket-Version: %d\x0d\x0a\x0d\x0a",
wsi->ietf_spec_revision);
/* done with these now */
free(wsi->c_path);
free(wsi->c_host);
free(wsi->c_origin);
if (wsi->c_origin)
free(wsi->c_origin);
/* prepare the expected server accept response */