[Asterisk-code-review] res/res http websocket: Don't send HTTP response fragmented. (asterisk[master])

Joshua Colp asteriskteam at digium.com
Sat Jul 4 18:26:43 CDT 2015


Joshua Colp has uploaded a new change for review.

  https://gerrit.asterisk.org/780

Change subject: res/res_http_websocket: Don't send HTTP response fragmented.
......................................................................

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
---
M res/res_http_websocket.c
1 file changed, 14 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/80/780/1

diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c
index 40aedff..ecae039 100644
--- a/res/res_http_websocket.c
+++ b/res/res_http_websocket.c
@@ -781,13 +781,6 @@
 			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 @@
 		 *    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 {
 

-- 
To view, visit https://gerrit.asterisk.org/780
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9b82c4ec2949b0bce692ad0bf6f7cea9709e7f69
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list