diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /netwerk/test/unit/test_304_headers.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_304_headers.js')
-rw-r--r-- | netwerk/test/unit/test_304_headers.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_304_headers.js b/netwerk/test/unit/test_304_headers.js new file mode 100644 index 0000000000..b3583663bf --- /dev/null +++ b/netwerk/test/unit/test_304_headers.js @@ -0,0 +1,91 @@ +"use strict"; + +const { HttpServer } = ChromeUtils.importESModule( + "resource://testing-common/httpd.sys.mjs" +); + +ChromeUtils.defineLazyGetter(this, "URL", function () { + return `http://localhost:${httpServer.identity.primaryPort}/test`; +}); + +let httpServer = null; + +function make_channel(url) { + return NetUtil.newChannel({ + uri: url, + loadUsingSystemPrincipal: true, + }).QueryInterface(Ci.nsIHttpChannel); +} + +function contentHandler(metadata, response) { + response.seizePower(); + let etag = ""; + try { + etag = metadata.getHeader("If-None-Match"); + } catch (ex) {} + + if (etag == "test-etag1") { + response.write("HTTP/1.1 304 Not Modified\r\n"); + + response.write("Link: <ref>; param1=value1\r\n"); + response.write("Link: <ref2>; param2=value2\r\n"); + response.write("Link: <ref3>; param1=value1\r\n"); + response.write("\r\n"); + response.finish(); + return; + } + + response.write("HTTP/1.1 200 OK\r\n"); + + response.write("ETag: test-etag1\r\n"); + response.write("Link: <ref>; param1=value1\r\n"); + response.write("Link: <ref2>; param2=value2\r\n"); + response.write("Link: <ref3>; param1=value1\r\n"); + response.write("\r\n"); + response.finish(); +} + +add_task(async function test() { + httpServer = new HttpServer(); + httpServer.registerPathHandler("/test", contentHandler); + httpServer.start(-1); + registerCleanupFunction(async () => { + await httpServer.stop(); + }); + + let chan = make_channel(Services.io.newURI(URL)); + chan.requestMethod = "HEAD"; + await new Promise(resolve => { + chan.asyncOpen({ + onStopRequest(req, status) { + equal(status, Cr.NS_OK); + equal(req.QueryInterface(Ci.nsIHttpChannel).responseStatus, 200); + equal( + req.QueryInterface(Ci.nsIHttpChannel).getResponseHeader("Link"), + "<ref>; param1=value1, <ref2>; param2=value2, <ref3>; param1=value1" + ); + resolve(); + }, + onStartRequest(req) {}, + onDataAvailable() {}, + }); + }); + + chan = make_channel(Services.io.newURI(URL)); + chan.requestMethod = "HEAD"; + await new Promise(resolve => { + chan.asyncOpen({ + onStopRequest(req, status) { + equal(status, Cr.NS_OK); + equal(req.QueryInterface(Ci.nsIHttpChannel).responseStatus, 200); + equal( + req.QueryInterface(Ci.nsIHttpChannel).getResponseHeader("Link"), + "<ref>; param1=value1, <ref2>; param2=value2, <ref3>; param1=value1" + ); + resolve(); + }, + onStartRequest(req) {}, + onDataAvailable() {}, + }); + }); +}); |