Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Proposed fix for wss:// protocol mismatch #84

Merged
merged 2 commits into from

3 participants

@crockpotveggies

I believe this will solve the issue where protocol mismatches were occuring when using Safari and other Apple products. The fix does a regex on the request ORIGIN and determines if it was HTTPS, thereby setting the response protocol to "wss://".

This was listed as a TODO in the code but looks like no one ever patched it up. Let me know if there's any issues and I will fix promptly.

@joewalnes
Owner

Nice work, tracking this down!

Minor request... Test for 'https://' instead of 'https'. This is for future robustness in case new protocols appear.

Also add your name to AUTHORS and update HISTORY.md.

Thanks
-Joe

@crockpotveggies

Updated the regular expression and also made sure that the protocol returned included the trailing slashes. That commit also includes updates to history and authors. Let me know if there's anything else I can do.

Using webbit for a new project and glad I could support it, looking forward to getting the new version disseminated!

@joewalnes joewalnes merged commit f83cfd5 into from
@joewalnes
Owner

Merged, thanks.

@aslakhellesoy

That's a 404:

igrigorik/em-websocket#82

Not sure what you're referring to here....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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://"; }
+ }
}
Something went wrong with that request. Please try again.