1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 Test if 204 response is cached.
8 1. Make first http request and return a 204 response.
9 2. Check if the first response is not cached.
10 3. Make second http request and check if the response is cached.
16 const { HttpServer
} = ChromeUtils
.importESModule(
17 "resource://testing-common/httpd.sys.mjs"
20 function test_handler(metadata
, response
) {
21 response
.setHeader("Content-Type", "text/html", false);
22 response
.setHeader("Cache-control", "max-age=9999", false);
23 response
.setStatusLine(metadata
.httpVersion
, 204, "No Content");
26 function make_channel(url
) {
27 let channel
= NetUtil
.newChannel({
29 loadUsingSystemPrincipal
: true,
30 }).QueryInterface(Ci
.nsIHttpChannel
);
34 async
function get_response(channel
, fromCache
) {
35 return new Promise(resolve
=> {
37 new ChannelListener((request
, buffer
, ctx
, isFromCache
) => {
41 `got response from cache = ${fromCache}`
49 async
function stop_server(httpserver
) {
50 return new Promise(resolve
=> {
51 httpserver
.stop(resolve
);
55 add_task(async
function () {
56 let httpserver
= new HttpServer();
57 httpserver
.registerPathHandler("/testdir", test_handler
);
59 const PORT
= httpserver
.identity
.primaryPort
;
60 const URI
= `http://localhost:${PORT}/testdir`;
62 await
get_response(make_channel(URI
, "GET"), false);
63 await
get_response(make_channel(URI
, "GET"), true);
65 await
stop_server(httpserver
);