1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
var httpserver = new HttpServer();
function setupChannel(suffix)
{
return NetUtil.newChannel({
uri: "http://localhost:" + httpserver.identity.primaryPort + suffix,
loadUsingSystemPrincipal: true
});
}
function checkValueAndTrigger(request, data, ctx)
{
do_check_eq("Ok", data);
httpserver.stop(do_test_finished);
}
function run_test()
{
// Allow all cookies.
Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
httpserver.registerPathHandler("/redirect1", redirectHandler1);
httpserver.registerPathHandler("/redirect2", redirectHandler2);
httpserver.start(-1);
// clear cache
evict_cache_entries();
// load first time
var channel = setupChannel("/redirect1");
channel.asyncOpen2(new ChannelListener(checkValueAndTrigger, null));
do_test_pending();
}
function redirectHandler1(metadata, response)
{
if (!metadata.hasHeader("Cookie")) {
response.setStatusLine(metadata.httpVersion, 302, "Found");
response.setHeader("Cache-Control", "max-age=600", false);
response.setHeader("Location", "/redirect2?query", false);
response.setHeader("Set-Cookie", "MyCookie=1", false);
} else {
response.setStatusLine(metadata.httpVersion, 200, "Ok");
response.setHeader("Content-Type", "text/plain");
response.bodyOutputStream.write("Ok", "Ok".length);
}
}
function redirectHandler2(metadata, response)
{
response.setStatusLine(metadata.httpVersion, 302, "Found");
response.setHeader("Location", "/redirect1", false);
}
|