fixes #783 WS transport - not connectable from Firefox
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4d0839e..aaeb9a4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,6 +2,7 @@
 #   Copyright (c) 2012-2013 Martin Sustrik  All rights reserved.
 #   Copyright (c) 2013 GoPivotal, Inc.  All rights reserved.
 #   Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved.
+#   Copyright 2016 Garrett D'Amore <garrett@damore.org>
 #
 #   Permission is hereby granted, free of charge, to any person obtaining a copy
 #   of this software and associated documentation files (the "Software"),
@@ -102,6 +103,12 @@
     utils/sem.c
     utils/sleep.h
     utils/sleep.c
+    utils/strcasecmp.c
+    utils/strcasecmp.h
+    utils/strcasestr.c
+    utils/strcasestr.h
+    utils/strncasecmp.c
+    utils/strncasecmp.h
     utils/thread.h
     utils/thread.c
     utils/wire.h
diff --git a/src/transports/ws/ws_handshake.c b/src/transports/ws/ws_handshake.c
index 5114aa0..26b7367 100644
--- a/src/transports/ws/ws_handshake.c
+++ b/src/transports/ws/ws_handshake.c
@@ -38,6 +38,7 @@
 #include "../../utils/wire.h"
 #include "../../utils/attr.h"
 #include "../../utils/random.h"
+#include "../../utils/strcasestr.h"
 
 #include <stddef.h>
 #include <string.h>
@@ -905,6 +906,7 @@
     /*  RFC 7230 3.1.1 Request Line: HTTP version. Note case sensitivity. */
     if (!nn_ws_match_token ("HTTP/1.1", &pos, 0, 0))
         return NN_WS_HANDSHAKE_RECV_MORE;
+
     if (!nn_ws_match_token (CRLF, &pos, 0, 0))
         return NN_WS_HANDSHAKE_RECV_MORE;
 
@@ -912,6 +914,9 @@
         header field. Match them one by one. */
     while (strlen (pos))
     {
+        const char *conn = NULL;
+        size_t conn_len = 0;
+fprintf(stderr, "POS is %s\n", pos);
         if (nn_ws_match_token ("Host:", &pos, 1, 0)) {
             rc = nn_ws_match_value (CRLF, &pos, 1, 1,
                 &self->host, &self->host_len);
@@ -933,8 +938,19 @@
         }
         else if (nn_ws_match_token ("Connection:",
             &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) {
-            rc = nn_ws_match_value (CRLF, &pos, 1, 1,
-                &self->conn, &self->conn_len);
+
+            rc = nn_ws_match_value (CRLF, &pos, 1, 1, &conn, &conn_len);
+
+            /*  The values here can be comma delimited, or they can be
+                listed as separate Connection headers.  We only care about
+                the presence of the Upgrade header, and we're willing to
+                assume well-formedness.  This crummy parse may let clients
+                send us a malformed header that we ought to reject, but
+                we'll just cite Postel's law here if anyone asks. */
+            self->conn = nn_strcasestr (conn, "upgrade");
+            if (self->conn != NULL) {
+                self->conn_len = strlen ("upgrade");
+            }
         }
         else if (nn_ws_match_token ("Sec-WebSocket-Version:",
             &pos, 1, 0) == NN_WS_HANDSHAKE_MATCH) {
diff --git a/src/utils/strcasecmp.c b/src/utils/strcasecmp.c
new file mode 100644
index 0000000..dec74c5
--- /dev/null
+++ b/src/utils/strcasecmp.c
@@ -0,0 +1,42 @@
+/*
+    Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"),
+    to deal in the Software without restriction, including without limitation
+    the rights to use, copy, modify, merge, publish, distribute, sublicense,
+    and/or sell copies of the Software, and to permit persons to whom
+    the Software is furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included
+    in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+    IN THE SOFTWARE.
+*/
+
+#include <ctype.h>
+#include "strcasecmp.h"
+
+int
+nn_strcasecmp(const char *a, const char *b)
+{
+	int rv;
+	for (;;) {
+		if ((*a == 0) && (*b == 0)) {
+			return (0);
+		}
+		if ((rv = (tolower(*a) - tolower(*b))) != 0) {
+			return (rv);
+		}
+		a++;
+		b++;
+	}
+	return (0);
+}
+
diff --git a/src/utils/strcasecmp.h b/src/utils/strcasecmp.h
new file mode 100644
index 0000000..96d8d82
--- /dev/null
+++ b/src/utils/strcasecmp.h
@@ -0,0 +1,28 @@
+/*
+    Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"),
+    to deal in the Software without restriction, including without limitation
+    the rights to use, copy, modify, merge, publish, distribute, sublicense,
+    and/or sell copies of the Software, and to permit persons to whom
+    the Software is furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included
+    in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+    IN THE SOFTWARE.
+*/
+
+#ifndef NN_STRCASECMP_INCLUDED
+#define NN_STRCASECMP_INCLUDED
+
+extern int nn_strcasecmp(const char *, const char *);
+
+#endif /* NN_STRCASECMP_INCLUDED */
diff --git a/src/utils/strcasestr.c b/src/utils/strcasestr.c
new file mode 100644
index 0000000..fe7fe76
--- /dev/null
+++ b/src/utils/strcasestr.c
@@ -0,0 +1,40 @@
+/*
+    Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"),
+    to deal in the Software without restriction, including without limitation
+    the rights to use, copy, modify, merge, publish, distribute, sublicense,
+    and/or sell copies of the Software, and to permit persons to whom
+    the Software is furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included
+    in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+    IN THE SOFTWARE.
+*/
+
+
+#include <stdio.h>
+#include <string.h>
+#include "strncasecmp.h"
+
+const char *
+nn_strcasestr(const char *str, const char *key)
+{
+	int len = strlen(key);
+
+	while (*str != '\0') {
+		if (nn_strncasecmp(str, key, len) == 0) {
+			return str;
+		}
+		str++;
+	}
+	return (NULL);
+}
diff --git a/src/utils/strcasestr.h b/src/utils/strcasestr.h
new file mode 100644
index 0000000..8c762c8
--- /dev/null
+++ b/src/utils/strcasestr.h
@@ -0,0 +1,28 @@
+/*
+    Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"),
+    to deal in the Software without restriction, including without limitation
+    the rights to use, copy, modify, merge, publish, distribute, sublicense,
+    and/or sell copies of the Software, and to permit persons to whom
+    the Software is furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included
+    in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+    IN THE SOFTWARE.
+*/
+
+#ifndef NN_STRCASESTR_INCLUDED
+#define NN_STRCASESTR_INCLUDED
+
+extern const char *nn_strcasestr(const char *, const char *);
+
+#endif /* NN_STRCASESTR */
diff --git a/src/utils/strncasecmp.c b/src/utils/strncasecmp.c
new file mode 100644
index 0000000..fe88f58
--- /dev/null
+++ b/src/utils/strncasecmp.c
@@ -0,0 +1,42 @@
+/*
+    Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"),
+    to deal in the Software without restriction, including without limitation
+    the rights to use, copy, modify, merge, publish, distribute, sublicense,
+    and/or sell copies of the Software, and to permit persons to whom
+    the Software is furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included
+    in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+    IN THE SOFTWARE.
+*/
+
+#include <ctype.h>
+#include "strncasecmp.h"
+
+int
+nn_strncasecmp(const char *a, const char *b, int len)
+{
+	int rv;
+	int count;
+	for (count = 0; count < len; count++) {
+		if ((*a == 0) && (*b == 0)) {
+			return (0);
+		}
+		if ((rv = tolower(*a) - tolower(*b)) != 0) {
+			return (rv);
+		}
+		a++;
+		b++;
+	}
+	return (0);
+}
diff --git a/src/utils/strncasecmp.h b/src/utils/strncasecmp.h
new file mode 100644
index 0000000..390b4ed
--- /dev/null
+++ b/src/utils/strncasecmp.h
@@ -0,0 +1,28 @@
+/*
+    Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"),
+    to deal in the Software without restriction, including without limitation
+    the rights to use, copy, modify, merge, publish, distribute, sublicense,
+    and/or sell copies of the Software, and to permit persons to whom
+    the Software is furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included
+    in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+    IN THE SOFTWARE.
+*/
+
+#ifndef NN_STRNCASECMP_INCLUDED
+#define NN_STRNCASECMP_INCLUDED
+
+extern int nn_strncasecmp(const char *, const char *, int);
+
+#endif /* NN_STRNCASECMP_INCLUDED */