From e708be7f6471a6090b26c61292dbaec3ede8af6c Mon Sep 17 00:00:00 2001
From: Arne Goedeke <el@laramies.com>
Date: Sat, 5 Nov 2016 12:07:17 +0100
Subject: [PATCH] Revert "WebSocket: Call either http_cb or ws_cb, not both, at
 the proper moment."

This reverts commit 7ce9c4aeb1723031b438d029aea55f8be336f9d6.
---
 .../HTTP.pmod/Server.pmod/Request.pike        | 14 +++--------
 lib/modules/Protocols.pmod/WebSocket.pmod     | 25 +++++++++++--------
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/lib/modules/Protocols.pmod/HTTP.pmod/Server.pmod/Request.pike b/lib/modules/Protocols.pmod/HTTP.pmod/Server.pmod/Request.pike
index 3ff1f6cfd8..b20a43a0d7 100644
--- a/lib/modules/Protocols.pmod/HTTP.pmod/Server.pmod/Request.pike
+++ b/lib/modules/Protocols.pmod/HTTP.pmod/Server.pmod/Request.pike
@@ -192,7 +192,7 @@ protected void read_cb(mixed dummy,string s)
       request_raw=v[1];
       parse_request();
 
-      if (parse_variables(0))
+      if (parse_variables())
          finalize();
    }
    else
@@ -348,16 +348,13 @@ private void read_cb_chunked( mixed dummy, string data )
   call_out(connection_timeout,connection_timeout_delay);
 }
 
-protected int parse_variables(int short)
+protected int parse_variables()
 {
   if (query!="")
     .http_decode_urlencoded_query(query,variables);
 
   flatten_headers();
 
-  if (short)
-    return 1;
-
   if ( request_headers->expect )
   {
     if ( lower_case(request_headers->expect) == "100-continue" )
@@ -434,10 +431,6 @@ protected void parse_post()
   }
 }
 
-protected int alternatecallback() {
-  return 0;
-}
-
 protected void finalize()
 {
   my_fd->set_blocking();
@@ -453,8 +446,7 @@ protected void finalize()
       foreach (request_headers->cookie/";";;string cookie)
         if (sscanf(String.trim_whites(cookie),"%s=%s",string a,string b)==2)
           cookies[a]=b;
-    if (!alternatecallback())
-      request_callback(this);
+    request_callback(this);
   }
 }
 
diff --git a/lib/modules/Protocols.pmod/WebSocket.pmod b/lib/modules/Protocols.pmod/WebSocket.pmod
index d00296d928..113f250d25 100644
--- a/lib/modules/Protocols.pmod/WebSocket.pmod
+++ b/lib/modules/Protocols.pmod/WebSocket.pmod
@@ -585,22 +585,25 @@ class Connection {
 class Request(function(array(string), Request:void) cb) {
     inherit Protocols.HTTP.Server.Request;
 
-    protected int alternatecallback() {
-      if (cb && has_index(request_headers, "sec-websocket-key")) {
-          string proto = request_headers["sec-websocket-protocol"];
-          array(string) protocols =  proto ? proto / ", " : ({});
+    protected void parse_request() {
+        ::parse_request();
+	if (cb && has_index(request_headers, "sec-websocket-key")) {
+	    string proto = request_headers["sec-websocket-protocol"];
+	    array(string) protocols =  proto ? proto / ", " : ({});
 #ifdef WEBSOCKET_DEBUG
-          werror("websocket request: %O %O\n", this, protocols);
+            werror("websocket request: %O %O\n", this, protocols);
 #endif
-          cb(protocols, this);
-          return 1;
-      }
-      return 0;
+	    cb(protocols, this);
+	}
     }
 
     protected int parse_variables() {
-	return ::parse_variables(
-          has_index(request_headers, "sec-websocket-key"));
+	if (!has_index(request_headers, "sec-websocket-key"))
+	    return ::parse_variables();
+	if (query!="")
+	    .HTTP.Server.http_decode_urlencoded_query(query,variables);
+	flatten_headers();
+	return 0;
     }
 
     //! Calling @[websocket_accept] completes the WebSocket connection
-- 
GitLab