libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 6ee22efc8bef57932da02c5d97204cf42395caee
parent d5571974e562efea6bd5bb30c09bdbfeab72533b
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed,  3 Dec 2014 23:47:40 +0000

From:
"Junker, Gregory" <gregory.junker@intel.com>
Date:
12/04/2014 12:30 AM
To:
"libmicrohttpd@gnu.org" <libmicrohttpd@gnu.org>

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




Diffstat:
MChangeLog | 4++++
Msrc/include/microhttpd.h | 2+-
Msrc/microhttpd/connection.c | 5+++--
3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/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 Call MHD_cleanup_connections() during MHD_DAEMON_INFO_CURRENT_CONNECTIONS processing for more accurate results. -MS diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -130,7 +130,7 @@ typedef intptr_t ssize_t; * Current version of the library. * 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00093801 +#define MHD_VERSION 0x00093802 /** * MHD-internal return code for "YES". diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -524,9 +524,10 @@ keepalive_possible (struct MHD_Connection *connection) { if (NULL == end) return MHD_YES; - if (0 == strcasecmp (end, "close")) + if ( (0 == strcasecmp (end, "close")) || + (0 == strcasecmp (end, "upgrade")) ) return MHD_NO; - return MHD_YES; + return MHD_YES; } if (0 == strcasecmp (connection->version, MHD_HTTP_VERSION_1_0))