Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | // |
michael@0 | 2 | // Verify that we hit the net if we discover a cycle of redirects |
michael@0 | 3 | // coming from cache. |
michael@0 | 4 | // |
michael@0 | 5 | |
michael@0 | 6 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 7 | |
michael@0 | 8 | var httpserver = new HttpServer(); |
michael@0 | 9 | var iteration = 0; |
michael@0 | 10 | |
michael@0 | 11 | function setupChannel(suffix) |
michael@0 | 12 | { |
michael@0 | 13 | var ios = |
michael@0 | 14 | Components.classes["@mozilla.org/network/io-service;1"] |
michael@0 | 15 | .getService(Ci.nsIIOService); |
michael@0 | 16 | var chan = ios.newChannel("http://localhost:" + |
michael@0 | 17 | httpserver.identity.primaryPort + suffix, "", null); |
michael@0 | 18 | var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); |
michael@0 | 19 | httpChan.requestMethod = "GET"; |
michael@0 | 20 | return httpChan; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function checkValueAndTrigger(request, data, ctx) |
michael@0 | 24 | { |
michael@0 | 25 | do_check_eq("Ok", data); |
michael@0 | 26 | httpserver.stop(do_test_finished); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function run_test() |
michael@0 | 30 | { |
michael@0 | 31 | httpserver.registerPathHandler("/redirect1", redirectHandler1); |
michael@0 | 32 | httpserver.registerPathHandler("/redirect2", redirectHandler2); |
michael@0 | 33 | httpserver.start(-1); |
michael@0 | 34 | |
michael@0 | 35 | // clear cache |
michael@0 | 36 | evict_cache_entries(); |
michael@0 | 37 | |
michael@0 | 38 | // load first time |
michael@0 | 39 | var channel = setupChannel("/redirect1"); |
michael@0 | 40 | channel.asyncOpen(new ChannelListener(checkValueAndTrigger, null), null); |
michael@0 | 41 | |
michael@0 | 42 | do_test_pending(); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function redirectHandler1(metadata, response) |
michael@0 | 46 | { |
michael@0 | 47 | // first time we return a cacheable 302 pointing to next redirect |
michael@0 | 48 | if (iteration < 1) { |
michael@0 | 49 | response.setStatusLine(metadata.httpVersion, 302, "Found"); |
michael@0 | 50 | response.setHeader("Cache-Control", "max-age=600", false); |
michael@0 | 51 | response.setHeader("Location", "/redirect2", false); |
michael@0 | 52 | |
michael@0 | 53 | // next time called we return 200 |
michael@0 | 54 | } else { |
michael@0 | 55 | response.setStatusLine(metadata.httpVersion, 200, "Ok"); |
michael@0 | 56 | response.setHeader("Cache-Control", "max-age=600", false); |
michael@0 | 57 | response.setHeader("Content-Type", "text/plain"); |
michael@0 | 58 | response.bodyOutputStream.write("Ok", "Ok".length); |
michael@0 | 59 | } |
michael@0 | 60 | iteration += 1; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | function redirectHandler2(metadata, response) |
michael@0 | 64 | { |
michael@0 | 65 | response.setStatusLine(metadata.httpVersion, 302, "Found"); |
michael@0 | 66 | response.setHeader("Cache-Control", "max-age=600", false); |
michael@0 | 67 | response.setHeader("Location", "/redirect1", false); |
michael@0 | 68 | } |