summaryrefslogtreecommitdiffstats
path: root/netwerk/test/mochitests/subResources.sjs
blob: ec2cfaa750483fa62f51e8fe5e0a12cfe7ba6979 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const kTwoDays = 2 * 24 * 60 * 60;
const kInTwoDays = new Date().getTime() + kTwoDays * 1000;

function getDateInTwoDays() {
  let date2 = new Date(kInTwoDays);
  let days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
  let months = [
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sep",
    "Oct",
    "Nov",
    "Dec",
  ];
  let day = date2.getUTCDate();
  if (day < 10) {
    day = "0" + day;
  }
  let month = months[date2.getUTCMonth()];
  let year = date2.getUTCFullYear();
  let hour = date2.getUTCHours();
  if (hour < 10) {
    hour = "0" + hour;
  }
  let minute = date2.getUTCMinutes();
  if (minute < 10) {
    minute = "0" + minute;
  }
  let second = date2.getUTCSeconds();
  if (second < 10) {
    second = "0" + second;
  }
  return (
    days[date2.getUTCDay()] +
    ", " +
    day +
    "-" +
    month +
    "-" +
    year +
    " " +
    hour +
    ":" +
    minute +
    ":" +
    second +
    " GMT"
  );
}

function handleRequest(aRequest, aResponse) {
  aResponse.setStatusLine(aRequest.httpVersion, 200);

  let suffix = " path=/; domain:.mochi.test";

  if (aRequest.queryString.includes("3")) {
    aResponse.setHeader(
      "Set-Cookie",
      "test3=value3; expires=Fri, 02-Jan-2037 00:00:01 GMT;" + suffix
    );
  } else if (aRequest.queryString.includes("4")) {
    let date2 = getDateInTwoDays();

    aResponse.setHeader(
      "Set-Cookie",
      "test4=value4; expires=" + date2 + ";" + suffix
    );
  }

  aResponse.setHeader("Content-Type", "text/javascript", false);
  aResponse.write("42;");
}