3 const { HttpServer } = ChromeUtils.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
7 ChromeUtils.defineLazyGetter(this, "URL", function () {
8 return `http://localhost:${httpServer.identity.primaryPort}/test`;
11 let httpServer = null;
13 function make_channel(url) {
14 return NetUtil.newChannel({
16 loadUsingSystemPrincipal: true,
17 }).QueryInterface(Ci.nsIHttpChannel);
20 function contentHandler(metadata, response) {
21 response.seizePower();
24 etag = metadata.getHeader("If-None-Match");
27 if (etag == "test-etag1") {
28 response.write("HTTP/1.1 304 Not Modified\r\n");
30 response.write("Link: <ref>; param1=value1\r\n");
31 response.write("Link: <ref2>; param2=value2\r\n");
32 response.write("Link: <ref3>; param1=value1\r\n");
33 response.write("\r\n");
38 response.write("HTTP/1.1 200 OK\r\n");
40 response.write("ETag: test-etag1\r\n");
41 response.write("Link: <ref>; param1=value1\r\n");
42 response.write("Link: <ref2>; param2=value2\r\n");
43 response.write("Link: <ref3>; param1=value1\r\n");
44 response.write("\r\n");
48 add_task(async function test() {
49 httpServer = new HttpServer();
50 httpServer.registerPathHandler("/test", contentHandler);
52 registerCleanupFunction(async () => {
53 await httpServer.stop();
56 let chan = make_channel(Services.io.newURI(URL));
57 chan.requestMethod = "HEAD";
58 await new Promise(resolve => {
60 onStopRequest(req, status) {
61 equal(status, Cr.NS_OK);
62 equal(req.QueryInterface(Ci.nsIHttpChannel).responseStatus, 200);
64 req.QueryInterface(Ci.nsIHttpChannel).getResponseHeader("Link"),
65 "<ref>; param1=value1, <ref2>; param2=value2, <ref3>; param1=value1"
69 onStartRequest(req) {},
74 chan = make_channel(Services.io.newURI(URL));
75 chan.requestMethod = "HEAD";
76 await new Promise(resolve => {
78 onStopRequest(req, status) {
79 equal(status, Cr.NS_OK);
80 equal(req.QueryInterface(Ci.nsIHttpChannel).responseStatus, 200);
82 req.QueryInterface(Ci.nsIHttpChannel).getResponseHeader("Link"),
83 "<ref>; param1=value1, <ref2>; param2=value2, <ref3>; param1=value1"
87 onStartRequest(req) {},