Ticket #9069: 9069.patch

File 9069.patch, 5.0 KB (added by arlolra, 5 years ago)
  • proxy/flashproxy.js

    From 8289dcd14fce965a74c2566b1f17ad83f4d8dcae Mon Sep 17 00:00:00 2001
    From: Arlo Breault <arlolra@gmail.com>
    Date: Sat, 2 Nov 2013 10:33:27 -0700
    Subject: [PATCH 1/3] 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 cb2ac9e..6942fa6 100644
    a b function format_addr(addr) { 
    426426   6455 section 5.6.) If not, we have to use base64-encoded text frames. It is
    427427   assumed that the client and relay endpoints always support binary frames. */
    428428function have_websocket_binary_frames() {
    429     var ua, matches;
     429    var ua, matches, browsers, reg;
    430430
    431431    ua = window.navigator.userAgent;
    432     if (ua === null)
     432    if (ua == null)
    433433        return false;
    434434
    435     /* We are cool for Chrome 16 or Safari 6.0. */
    436 
    437     matches = ua.match(/\bchrome\/(\d+)/i);
    438     if (matches !== null && Number(matches[1]) >= 16)
    439         return true;
    440 
    441     matches = ua.match(/\bversion\/(\d+)/i);
    442     if (ua.match(/\bsafari\b/i) && !ua.match(/\bchrome\b/i)
    443         && Number(matches[1]) >= 6)
    444         return true;
     435    browsers = [
     436      { idString: "Chrome",  verString: "Chrome",  version: 16 },
     437      { idString: "Safari",  verString: "Version", version: 6  },
     438    ];
     439
     440    for (var i = 0; i < browsers.length; i++) {
     441      reg = "\\b" + browsers[i].idString + "\\b";
     442      if (ua.match(new RegExp(reg, "i")) == null)
     443          continue;
     444      reg = "\\b" + browsers[i].verString + "\\/(\\d+)";
     445      matches = ua.match(new RegExp(reg, "i"));
     446      return (matches != null
     447          && Number(matches[1]) >= browsers[i].version) ? true : false;
     448    }
    445449
    446450    return false;
    447451}
  • proxy/flashproxy-test.js

    -- 
    1.8.4.2
    
    From aac43244494d07764d4e88010af6a8e079c85caa Mon Sep 17 00:00:00 2001
    From: Arlo Breault <arlolra@gmail.com>
    Date: Sat, 2 Nov 2013 10:35:25 -0700
    Subject: [PATCH 2/3] Add tests for have_websocket_binary_frames().
    
    ---
     proxy/flashproxy-test.js | 21 +++++++++++++++++++++
     1 file changed, 21 insertions(+)
    
    diff --git a/proxy/flashproxy-test.js b/proxy/flashproxy-test.js
    index e2b5a43..e775f53 100755
    a b function test_lang_keys() { 
    322322    }
    323323}
    324324
     325function test_have_websocket_binary_frames() {
     326    var TESTS = [
     327        { ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36", expected: true },
     328        { ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1", expected: true },
     329        { expected: false },  // no userAgent
     330    ];
     331    var _navigator = window.navigator;
     332    for (var i = 0; i < TESTS.length; i++) {
     333        var test = TESTS[i];
     334        window.navigator = { userAgent: test.ua };
     335        var actual = have_websocket_binary_frames();
     336
     337        if (objects_equal(actual, test.expected))
     338            pass(test.ua);
     339        else
     340            fail(test.ua, test.expected, actual);
     341    }
     342    window.navigator = _navigator;
     343}
     344
    325345test_build_url();
    326346test_parse_cookie_string();
    327347test_parse_query_string();
    test_get_param_boolean(); 
    329349test_parse_addr_spec();
    330350test_get_param_addr();
    331351test_lang_keys();
     352test_have_websocket_binary_frames();
    332353
    333354if (num_failed == 0)
    334355    quit(0);
  • proxy/flashproxy-test.js

    -- 
    1.8.4.2
    
    From 147a62261ded7f01d23e4471e22f3b4b35ac7784 Mon Sep 17 00:00:00 2001
    From: Arlo Breault <arlolra@gmail.com>
    Date: Sat, 2 Nov 2013 10:36:16 -0700
    Subject: [PATCH 3/3] Add Firefox 11 to have_websocket_binary_frames().
    
    ---
     proxy/flashproxy-test.js | 2 ++
     proxy/flashproxy.js      | 1 +
     2 files changed, 3 insertions(+)
    
    diff --git a/proxy/flashproxy-test.js b/proxy/flashproxy-test.js
    index e775f53..976fd44 100755
    a b function test_lang_keys() { 
    324324
    325325function test_have_websocket_binary_frames() {
    326326    var TESTS = [
     327        { ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:10.0.2) Gecko/20100101 Firefox/10.0.2", expected: false },
     328        { ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:11.0) Gecko/20100101 Firefox/11.0", expected: true },
    327329        { ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36", expected: true },
    328330        { ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1", expected: true },
    329331        { expected: false },  // no userAgent
  • proxy/flashproxy.js

    diff --git a/proxy/flashproxy.js b/proxy/flashproxy.js
    index 6942fa6..7a9e75d 100644
    a b function have_websocket_binary_frames() { 
    435435    browsers = [
    436436      { idString: "Chrome",  verString: "Chrome",  version: 16 },
    437437      { idString: "Safari",  verString: "Version", version: 6  },
     438      { idString: "Firefox", verString: "Firefox", version: 11 }
    438439    ];
    439440
    440441    for (var i = 0; i < browsers.length; i++) {