summaryrefslogtreecommitdiffstats
path: root/netwerk/test/httpserver/test/test_header_array.js
blob: 18a08cce519a539abba294e0dc20e504027c3482 (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// test that special headers are sent as an array of headers with the same name

var srv;

function run_test() {
  srv;

  srv = createServer();
  srv.registerPathHandler("/path-handler", pathHandler);
  srv.start(-1);

  runHttpTests(tests, testComplete(srv));
}

/** **********
 * HANDLERS *
 ************/

function pathHandler(request, response) {
  response.setHeader("Cache-Control", "no-cache", false);

  response.setHeader("Proxy-Authenticate", "First line 1", true);
  response.setHeader("Proxy-Authenticate", "Second line 1", true);
  response.setHeader("Proxy-Authenticate", "Third line 1", true);

  response.setHeader("WWW-Authenticate", "Not merged line 1", false);
  response.setHeader("WWW-Authenticate", "Not merged line 2", true);

  response.setHeader("WWW-Authenticate", "First line 2", false);
  response.setHeader("WWW-Authenticate", "Second line 2", true);
  response.setHeader("WWW-Authenticate", "Third line 2", true);

  response.setHeader("X-Single-Header-Merge", "Single 1", true);
  response.setHeader("X-Single-Header-Merge", "Single 2", true);
}

/** *************
 * BEGIN TESTS *
 ***************/

XPCOMUtils.defineLazyGetter(this, "tests", function () {
  return [
    new Test(
      "http://localhost:" + srv.identity.primaryPort + "/path-handler",
      null,
      check
    ),
  ];
});

function check(ch) {
  var headerValue;

  headerValue = ch.getResponseHeader("Proxy-Authenticate");
  Assert.equal(headerValue, "First line 1\nSecond line 1\nThird line 1");
  headerValue = ch.getResponseHeader("WWW-Authenticate");
  Assert.equal(headerValue, "First line 2\nSecond line 2\nThird line 2");
  headerValue = ch.getResponseHeader("X-Single-Header-Merge");
  Assert.equal(headerValue, "Single 1,Single 2");
}