changeset 1796:e1fd234baac0

Tests: added HEAD method tests for js fetch API.
author Dmitry Volyntsev <xeioex@nginx.com>
date Tue, 27 Sep 2022 16:11:56 -0700
parents 88a098b00534
children 0b06942f0b8b
files js_fetch.t
diffstat 1 files changed, 28 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/js_fetch.t
+++ b/js_fetch.t
@@ -283,10 +283,17 @@ my $p2 = port(8082);
     }
 
     async function body_special(r) {
-        let reply = await ngx.fetch(`http://127.0.0.1:$p2/\${r.args.loc}`);
+        let opts = {};
+
+        if (r.args.method) {
+            opts.method = r.args.method;
+        }
+
+        let reply = await ngx.fetch(`http://127.0.0.1:$p2/\${r.args.loc}`,
+                                    opts);
         let body = await reply.text();
 
-        r.return(200, body);
+        r.return(200, body != '' ? body : '<empty>');
     }
 
     async function header_iter(r) {
@@ -369,7 +376,7 @@ my $p2 = port(8082);
                      chain, chunked, header, header_iter, multi, loc, property};
 EOF
 
-$t->try_run('no njs.fetch')->plan(31);
+$t->try_run('no njs.fetch')->plan(33);
 
 $t->run_daemon(\&http_daemon, port(8082));
 $t->waitforsocket('127.0.0.1:' . port(8082));
@@ -465,6 +472,17 @@ like(http_get('/body_special?loc=no_cont
 
 }
 
+TODO: {
+local $TODO = 'not yet'
+	unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.8';
+
+like(http_get('/body_special?loc=head&method=HEAD'),
+	qr/200 OK.*<empty>$/s, 'fetch head method');
+like(http_get('/body_special?loc=length&method=head'),
+	qr/200 OK.*<empty>$/s, 'fetch head method lower case');
+
+}
+
 ###############################################################################
 
 sub recode {
@@ -566,6 +584,13 @@ sub http_daemon {
 				CRLF .
 				"unfinished" . CRLF;
 
+		} elsif ($uri eq '/head') {
+			print $client
+				"HTTP/1.1 200 OK" . CRLF .
+				"Content-Length: 100" . CRLF .
+				"Connection: close" . CRLF .
+				CRLF;
+
 		} elsif ($uri eq '/parted') {
 			print $client
 				"HTTP/1.1 200 OK" . CRLF .