Proposed fix for wss:// protocol mismatch #84

Merged
merged 2 commits into from Mar 29, 2012
View
3 AUTHORS
@@ -14,4 +14,5 @@ Neil Dunn
Nathan Mische
Phil Dawes
Alex Silverstein
-Michael Rykov
+Michael Rykov
+Justin Long
View
7 HISTORY.md
@@ -1,3 +1,10 @@
+0.4.7 (2012-03-29)
+==================
+
+[Full changelog](https://github.com/webbit/webbit/compare/v0.4.6...v0.4.7)
+
+* Now returns the appropriate protocol when responding to [secure websockets](https://github.com/igrigorik/em-websocket/issues/82). (Justin Long)
+
0.4.6 (2012-02-23)
==================
View
7 src/main/java/org/webbitserver/netty/Hixie75.java
@@ -58,7 +58,10 @@ public ChannelHandler createEncoder() {
}
private String getWebSocketLocation(HttpRequest req) {
- // TODO: It should be wss if it was https
- return "ws://" + req.getHeader(HttpHeaders.Names.HOST) + req.getUri();
+ return getWebSocketProtocol(req) + req.getHeader(HttpHeaders.Names.HOST) + req.getUri();
+ }
+
+ private String getWebSocketProtocol(HttpRequest req) {
+ if(req.getHeader(HttpHeaders.Names.ORIGIN).matches("/^https:\\/\\//")) { return "wss://"; } else { return "ws://"; }
}
}
View
7 src/main/java/org/webbitserver/netty/Hixie76.java
@@ -87,7 +87,10 @@ public ChannelHandler createEncoder() {
}
private String getWebSocketLocation(HttpRequest req) {
- // TODO: It should be wss if it was https
- return "ws://" + req.getHeader(HttpHeaders.Names.HOST) + req.getUri();
+ return getWebSocketProtocol(req) + req.getHeader(HttpHeaders.Names.HOST) + req.getUri();
}
+
+ private String getWebSocketProtocol(HttpRequest req) {
+ if(req.getHeader(HttpHeaders.Names.ORIGIN).matches("/^https:\\/\\//")) { return "wss://"; } else { return "ws://"; }
+ }
}