summaryrefslogtreecommitdiff
path: root/res/res_http_websocket.c
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2015-07-04 20:22:01 -0300
committerJoshua Colp <jcolp@digium.com>2015-07-04 18:26:43 -0500
commitf35a4b8525c86d98187c142484f254ef0ff257e9 (patch)
tree94ed11b30db79dc319ecfcd64dbfac6ae11e6b1d /res/res_http_websocket.c
parent2c17515f3c53c4ec5846b1621a373ba7b5628f74 (diff)
res/res_http_websocket: Don't send HTTP response fragmented.
This change makes it so that when accepting a WebSocket connection the HTTP response is sent as one packet instead of fragmented. Browsers don't like it when you send it fragmented. ASTERISK-25103 Change-Id: I9b82c4ec2949b0bce692ad0bf6f7cea9709e7f69
Diffstat (limited to 'res/res_http_websocket.c')
-rw-r--r--res/res_http_websocket.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c
index 40aedff72..ecae03919 100644
--- a/res/res_http_websocket.c
+++ b/res/res_http_websocket.c
@@ -781,13 +781,6 @@ int AST_OPTIONAL_API_NAME(ast_websocket_uri_cb)(struct ast_tcptls_session_instan
return 0;
}
- fprintf(ser->f, "HTTP/1.1 101 Switching Protocols\r\n"
- "Upgrade: %s\r\n"
- "Connection: Upgrade\r\n"
- "Sec-WebSocket-Accept: %s\r\n",
- upgrade,
- websocket_combine_key(key, base64, sizeof(base64)));
-
/* RFC 6455, Section 4.1:
*
* 6. If the response includes a |Sec-WebSocket-Protocol| header
@@ -798,11 +791,23 @@ int AST_OPTIONAL_API_NAME(ast_websocket_uri_cb)(struct ast_tcptls_session_instan
* Connection_.
*/
if (protocol) {
- fprintf(ser->f, "Sec-WebSocket-Protocol: %s\r\n",
+ fprintf(ser->f, "HTTP/1.1 101 Switching Protocols\r\n"
+ "Upgrade: %s\r\n"
+ "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Accept: %s\r\n"
+ "Sec-WebSocket-Protocol: %s\r\n\r\n",
+ upgrade,
+ websocket_combine_key(key, base64, sizeof(base64)),
protocol);
+ } else {
+ fprintf(ser->f, "HTTP/1.1 101 Switching Protocols\r\n"
+ "Upgrade: %s\r\n"
+ "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Accept: %s\r\n\r\n",
+ upgrade,
+ websocket_combine_key(key, base64, sizeof(base64)));
}
- fprintf(ser->f, "\r\n");
fflush(ser->f);
} else {