[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [flashproxy/master] Refactor have_websocket_binary_frames().
commit b30065357f4f99b7faf4c4f384d387e39a21f38c
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date: Sat Nov 2 10:33:27 2013 -0700
Refactor have_websocket_binary_frames().
---
proxy/flashproxy.js | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/proxy/flashproxy.js b/proxy/flashproxy.js
index b739464..fad3b7e 100644
--- a/proxy/flashproxy.js
+++ b/proxy/flashproxy.js
@@ -426,22 +426,26 @@ function format_addr(addr) {
6455 section 5.6.) If not, we have to use base64-encoded text frames. It is
assumed that the client and relay endpoints always support binary frames. */
function have_websocket_binary_frames() {
- var ua, matches;
+ var ua, matches, browsers, reg;
ua = window.navigator.userAgent;
- if (ua === null)
+ if (ua == null)
return false;
- /* We are cool for Chrome 16 or Safari 6.0. */
-
- matches = ua.match(/\bchrome\/(\d+)/i);
- if (matches !== null && Number(matches[1]) >= 16)
- return true;
-
- matches = ua.match(/\bversion\/(\d+)/i);
- if (ua.match(/\bsafari\b/i) && !ua.match(/\bchrome\b/i)
- && Number(matches[1]) >= 6)
- return true;
+ browsers = [
+ { idString: "Chrome", verString: "Chrome", version: 16 },
+ { idString: "Safari", verString: "Version", version: 6 },
+ ];
+
+ for (var i = 0; i < browsers.length; i++) {
+ reg = "\\b" + browsers[i].idString + "\\b";
+ if (ua.match(new RegExp(reg, "i")) == null)
+ continue;
+ reg = "\\b" + browsers[i].verString + "\\/(\\d+)";
+ matches = ua.match(new RegExp(reg, "i"));
+ return (matches != null
+ && Number(matches[1]) >= browsers[i].version) ? true : false;
+ }
return false;
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits