Переглянути джерело

From:
"Junker, Gregory" <[email protected]>
Date:
12/04/2014 12:30 AM
To:
"[email protected]" <[email protected]>

Hi all

I need a tiny addition made to connection.c.

In keepalive_possible(), can we change the line that says

if (0 == strcasecmp (end, "close"))

to



if (0 == strcasecmp (end, "close") || 0 == strcasecmp (end, "upgrade"))

?

This would make it possible to use libmicrohttpd in a WebSocket (RFC6455) environment. Currently, the way that the WebSocket protocol works, it sends "Connection: Upgrade" in the headers with the initial handshake, which causes this check to fail and (ultimately) insert "Connection: Keep-Alive" in the response headers (which cause any compliant WebSocket client to fail the handshake, since it needs "Connection: Upgrade" in the response headers, and there is no way to remove this keepalive header from the response from outside of MHD, as it is added automatically to the response buffer).

Note that this is only an HTTP/1.1 issue, AFAIK (I am pretty sure, though not positive, that WebSocket is not compatible with HTTP/1.0).

Thanks!
Greg

Christian Grothoff 11 роки тому
батько
коміт
6ee22efc8b
3 змінених файлів з 8 додано та 3 видалено
  1. 4 0
      ChangeLog
  2. 1 1
      src/include/microhttpd.h
  3. 3 2
      src/microhttpd/connection.c

+ 4 - 0
ChangeLog

@@ -1,3 +1,7 @@
+Thu Dec  4 00:43:10 CET 2014
+	If "Connection: upgrade" is requested, do not add
+	"Connection: Keep-Alive" in the response. -GJ
+
 Tue Nov 18 13:52:29 CET 2014
 Tue Nov 18 13:52:29 CET 2014
 	Call MHD_cleanup_connections() during MHD_DAEMON_INFO_CURRENT_CONNECTIONS
 	Call MHD_cleanup_connections() during MHD_DAEMON_INFO_CURRENT_CONNECTIONS
 	processing for more accurate results. -MS
 	processing for more accurate results. -MS

+ 1 - 1
src/include/microhttpd.h

@@ -130,7 +130,7 @@ typedef intptr_t ssize_t;
  * Current version of the library.
  * Current version of the library.
  * 0x01093001 = 1.9.30-1.
  * 0x01093001 = 1.9.30-1.
  */
  */
-#define MHD_VERSION 0x00093801
+#define MHD_VERSION 0x00093802
 
 
 /**
 /**
  * MHD-internal return code for "YES".
  * MHD-internal return code for "YES".

+ 3 - 2
src/microhttpd/connection.c

@@ -524,9 +524,10 @@ keepalive_possible (struct MHD_Connection *connection)
   {
   {
     if (NULL == end)
     if (NULL == end)
       return MHD_YES;
       return MHD_YES;
-    if (0 == strcasecmp (end, "close"))
+    if ( (0 == strcasecmp (end, "close")) ||
+         (0 == strcasecmp (end, "upgrade")) )
       return MHD_NO;
       return MHD_NO;
-    return MHD_YES;
+   return MHD_YES;
   }
   }
   if (0 == strcasecmp (connection->version,
   if (0 == strcasecmp (connection->version,
                        MHD_HTTP_VERSION_1_0))
                        MHD_HTTP_VERSION_1_0))