summaryrefslogtreecommitdiffstats
path: root/netwerk/test/mochitests/test_accept_header.sjs
blob: 7d00017903d5af4eebabb087758256977d97fbac (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
function handleRequest(request, response) {
  response.setStatusLine(request.httpVersion, "200", "OK");
  dump(`test_accept_header ${request.path}?${request.queryString}\n`);

  if (request.queryString == "worker") {
    response.setHeader("Content-Type", "text/javascript", false);
    response.write("postMessage(42)");

    setState("data", JSON.stringify({type: "worker", accept: request.getHeader("Accept") }));
    return;
  }

  if (request.queryString == "image") {
    // A 1x1 PNG image.
    // Source: https://commons.wikimedia.org/wiki/File:1x1.png (Public Domain)
    const IMAGE = atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAA" +
                       "ACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=");

    response.setHeader("Content-Type", "image/png", false);
    response.write(IMAGE);

    setState("data", JSON.stringify({type: "image", accept: request.getHeader("Accept") }));
    return;
  }

  if (request.queryString == "style") {
    response.setHeader("Content-Type", "text/css", false);
    response.write("");

    setState("data", JSON.stringify({type: "style", accept: request.getHeader("Accept") }));
    return;
  }

  if (request.queryString == "iframe") {
    response.setHeader("Content-Type", "text/html", false);
    response.write("<h1>Hello world!</h1>");

    setState("data", JSON.stringify({type: "iframe", accept: request.getHeader("Accept") }));
    return;
  }

  if (request.queryString == "get") {
    response.setHeader("Content-Type", "application/json", false);
    response.write(getState("data"));

    setState("data", "");
    return;
  }
}