# HG changeset patch # User Dmitry Volyntsev # Date 1664320316 25200 # Node ID e1fd234baac003fc624719a30b3863e83c8c1b02 # Parent 88a098b00534ccd403c0704589a94e232f29029f Tests: added HEAD method tests for js fetch API. diff --git a/js_fetch.t b/js_fetch.t --- 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 : ''); } 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.*$/s, 'fetch head method'); +like(http_get('/body_special?loc=length&method=head'), + qr/200 OK.*$/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 .