Permalink
Browse files

look at upgrade header rather than connection for identifying handshakes

  • Loading branch information...
ztellman committed Feb 22, 2012
1 parent 5ce859f commit 8f3877e02a7301bc5b3a18d16f4e7fea2e6306d9
Showing with 23 additions and 21 deletions.
  1. +2 −2 project.clj
  2. +3 −1 src/aleph/http/websocket.clj
  3. +18 −18 test/websocket.html
View
@@ -9,7 +9,7 @@
[org.clojure/tools.logging "0.2.3"]
[org.clojure/data.json "0.1.1"]
[org.clojure.contrib/prxml "1.3.0-alpha4"]
[io.netty/netty "3.3.0.Final"]
[io.netty/netty "3.3.1.Final"]
[clj-http "0.1.3"]
[lamina "0.4.1-alpha1"]
[gloss "0.2.1-alpha2-SNAPSHOT"]
@@ -18,7 +18,7 @@
:multi-deps {:all [[org.clojure/tools.logging "0.2.3"]
[org.clojure/data.json "0.1.1"]
[org.clojure.contrib/prxml "1.3.0-alpha4"]
[io.netty/netty "3.3.0.Final"]
[io.netty/netty "3.3.1.Final"]
[clj-http "0.1.3"]
[lamina "0.4.1-alpha1"]
[gloss "0.2.1-alpha2-SNAPSHOT"]
@@ -13,6 +13,8 @@
[aleph.http core]
[aleph.http.server requests responses]
[aleph formats netty])
(:require
[clojure.string :as str])
(:import
[org.jboss.netty.handler.codec.http
HttpRequest
@@ -41,7 +43,7 @@
(set! *warn-on-reflection* true)
(defn create-handshaker [^HttpRequest req]
(when (= "Upgrade" (.getHeader req "Connection"))
(when (= "websocket" (str/lower-case (.getHeader req "Upgrade")))
(->
(WebSocketServerHandshakerFactory.
(str "ws://" (.getHeader req "Host") (.getUri req))
View
@@ -1,9 +1,9 @@
<html>
<head>
<title>WebSocket</title>
<script>
<head>
<title>WebSocket</title>
<script>
var socket;
function openWebSocket() {
if (window.WebSocket) {
socket = new WebSocket('ws://127.0.0.1:10000/socket?a=b&c=d');
@@ -14,15 +14,15 @@
alert('Your browser does not support WebSockets yet.');
}
}
function closeWebSocket() {
socket.close();
}
function $(id) {
return document.getElementById(id);
}
function send(message) {
if (!window.WebSocket) { return; }
if (socket.readyState == (WebSocket.OPEN || 1)) {
@@ -36,16 +36,16 @@
// parse response: json or xml, etc
$('out').innerHTML = response;
}
</script>
</head>
<body onload='openWebSocket()' onunload='closeWebSocket()'>
<INPUT type="button" value="Send" name="button1" onClick="send('check')">
</script>
</head>
<body onload='openWebSocket()' onunload='closeWebSocket()'>
<INPUT type="button" value="Send" name="button1" onClick="send('check')">
<INPUT type="button" value="Close" name="button2" onClick="closeWebSocket()">
<div id='out'></div>
<!-- more html here -->
</body>
<div id='out'></div>
<!-- more html here -->
</body>
</html>

0 comments on commit 8f3877e

Please sign in to comment.