瀏覽代碼

Merge pull request #1 from feneuilflo/ws-subprotocol

remove leading whitespaces when matching websocket protocols
feneuilflo 8 年之前
父節點
當前提交
1e718da63c
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      src/civetweb.c

+ 4 - 2
src/civetweb.c

@@ -9826,7 +9826,8 @@ handle_websocket_request(struct mg_connection *conn,
 				sep = strchr(protocol, ',');
 				curSubProtocol = protocol;
 				len = sep ? (unsigned long)(sep - protocol) : strlen(protocol);
-				protocol = sep ? sep + 1 : NULL;
+				while(sep && isspace(*++sep)); // ignore leading whitespaces
+				protocol = sep;
 
 
 				for (idx = 0; idx < subprotocols->nb_subprotocols; idx++) {
@@ -9861,7 +9862,8 @@ handle_websocket_request(struct mg_connection *conn,
 				 * and use it to select one protocol among those the client has
 				 * offered.
 				 */
-				conn->request_info.acceptedWebSocketSubprotocol = (sep + 1);
+				while(isspace(*++sep)); // ignore leading whitespaces
+				conn->request_info.acceptedWebSocketSubprotocol = sep;
 			}
 		}