annotate js_fetch_objects.t @ 1854:0152ce2de27f

Tests: removed forbidden header js tests.
author Dmitry Volyntsev <xeioex@nginx.com>
date Wed, 10 May 2023 18:25:20 -0700
parents de6aeda5c274
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
2
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
3 # (C) Dmitry Volyntsev
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
5
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
6 # Tests for http njs module, fetch objects.
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
7
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
8 ###############################################################################
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
9
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
10 use warnings;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
11 use strict;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
12
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
13 use Test::More;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
14
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
16
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
17 use lib 'lib';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
19
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
20 ###############################################################################
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
21
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
24
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http rewrite/)
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
26 ->write_file_expand('nginx.conf', <<'EOF');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
27
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
29
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
30 daemon off;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
31
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
32 events {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
33 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
34
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
35 http {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
37
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
38 js_import test.js;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
39
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
40 server {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
41 listen 127.0.0.1:8080;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
42 server_name localhost;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
43
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
44 location /njs {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
45 js_content test.njs;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
46 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
47
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
48 location /headers {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
49 js_content test.headers;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
50 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
51
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
52 location /request {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
53 js_content test.request;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
54 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
55
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
56 location /response {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
57 js_content test.response;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
58 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
59
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
60 location /fetch {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
61 js_content test.fetch;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
62 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
63
1821
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
64 location /fetch_multi_header {
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
65 js_content test.fetch_multi_header;
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
66 }
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
67
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
68 location /method {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
69 return 200 $request_method;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
70 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
71
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
72 location /header {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
73 return 200 $http_a;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
74 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
75
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
76 location /body {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
77 js_content test.body;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
78 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
79 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
80 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
81
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
82 EOF
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
83
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
84 my $p0 = port(8080);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
85
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
86 $t->write_file('test.js', <<EOF);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
87 function test_njs(r) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
88 r.return(200, njs.version);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
89 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
90
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
91 function header(r) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
92 r.return(200, r.headersIn.a);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
93 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
94
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
95 function body(r) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
96 r.return(201, r.requestText);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
97 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
98
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
99 async function run(r, tests) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
100 var fails = [];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
101 for (var i = 0; i < tests.length; i++) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
102 var v, t = tests[i];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
103
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
104 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
105 v = await t[1]();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
106
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
107 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
108 v = e.message;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
109 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
110
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
111 if (v != t[2]) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
112 fails.push(`\${t[0]}: got "\${v}" expected: "\${t[2]}"\n`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
113 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
114 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
115
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
116 r.return(fails.length ? 400 : 200, fails);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
117 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
118
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
119 async function headers(r) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
120 const tests = [
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
121 ['empty', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
122 var h = new Headers();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
123 return h.get('a');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
124 }, null],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
125 ['normal', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
126 var h = new Headers({a: 'X', b: 'Z'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
127 return `\${h.get('a')} \${h.get('B')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
128 }, 'X Z'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
129 ['trim value', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
130 var h = new Headers({a: ' X '});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
131 return h.get('a');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
132 }, 'X'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
133 ['invalid header name', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
134 const valid = "!#\$\%&'*+-.^_`|~0123456789";
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
135
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
136 for (var i = 0; i < 128; i++) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
137 var c = String.fromCodePoint(i);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
138
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
139 if (valid.indexOf(c) != -1 || /[a-zA-Z]+/.test(c)) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
140 continue;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
141 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
142
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
143 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
144 new Headers([[c, 'a']]);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
145 throw new Error(
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
146 `header with "\${c}" (\${i}) should throw`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
147
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
148 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
149 if (e.message != 'invalid header name') {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
150 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
151 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
152 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
153 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
154
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
155 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
156
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
157 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
158 ['invalid header value', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
159 var h = new Headers({A: 'aa\x00a'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
160 }, 'invalid header value'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
161 ['combine', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
162 var h = new Headers({a: 'X', A: 'Z'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
163 return h.get('a');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
164 }, 'X, Z'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
165 ['combine2', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
166 var h = new Headers([['A', 'x'], ['a', 'z']]);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
167 return h.get('a');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
168 }, 'x, z'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
169 ['combine3', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
170 var h = new Headers();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
171 h.append('a', 'A');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
172 h.append('a', 'B');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
173 h.append('a', 'C');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
174 h.append('a', 'D');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
175 h.append('a', 'E');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
176 h.append('a', 'F');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
177 return h.get('a');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
178 }, 'A, B, C, D, E, F'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
179 ['getAll', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
180 var h = new Headers({a: 'X', A: 'Z'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
181 return njs.dump(h.getAll('a'));
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
182 }, "['X','Z']"],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
183 ['inherit', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
184 var h = new Headers({a: 'X', b: 'Y'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
185 var h2 = new Headers(h);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
186 h2.append('c', 'Z');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
187 return h2.has('a') && h2.has('B') && h2.has('c');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
188 }, true],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
189 ['delete', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
190 var h = new Headers({a: 'X', b: 'Z'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
191 h.delete('b');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
192 return h.get('a') && !h.get('b');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
193 }, true],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
194 ['forEach', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
195 var r = [];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
196 var h = new Headers({a: '0', b: '1', c: '2'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
197 h.delete('b');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
198 h.append('z', '3');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
199 h.append('a', '4');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
200 h.append('q', '5');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
201 h.forEach((v, k) => { r.push(`\${v}:\${k}`)})
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
202 return r.join('|');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
203 }, 'a:0, 4|c:2|q:5|z:3'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
204 ['set', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
205 var h = new Headers([['A', 'x'], ['a', 'y'], ['a', 'z']]);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
206 h.set('a', '#');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
207 return h.get('a');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
208 }, '#'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
209 ];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
210
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
211 run(r, tests);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
212 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
213
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
214 async function request(r) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
215 const tests = [
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
216 ['empty', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
217 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
218 new Request();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
219 throw new Error(`Request() should throw`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
220
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
221 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
222 if (e.message != '1st argument is required') {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
223 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
224 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
225 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
226
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
227 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
228
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
229 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
230 ['normal', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
231 var r = new Request("http://nginx.org",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
232 {headers: {a: 'X', b: 'Y'}});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
233 return `\${r.url}: \${r.method} \${r.headers.a}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
234 }, 'http://nginx.org: GET X'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
235 ['url trim', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
236 var r = new Request("\\x00\\x01\\x02\\x03\\x05\\x06\\x07\\x08"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
237 + "\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\x0f"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
238 + "\\x10\\x11\\x12\\x13\\x14\\x15\\x16"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
239 + "\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
240 + "\\x1e\\x1f\\x20http://nginx.org\\x00"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
241 + "\\x01\\x02\\x03\\x05\\x06\\x07\\x08"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
242 + "\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\x0f"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
243 + "\\x10\\x11\\x12\\x13\\x14\\x15\\x16"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
244 + "\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
245 + "\\x1e\\x1f\\x20");
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
246 return r.url;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
247 }, 'http://nginx.org'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
248 ['read only', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
249 var r = new Request("http://nginx.org");
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
250
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
251 const props = ['bodyUsed', 'cache', 'credentials', 'headers',
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
252 'method', 'mode', 'url'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
253 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
254 props.forEach(prop => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
255 r[prop] = 1;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
256 throw new Error(
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
257 `setting read-only \${prop} should throw`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
258 })
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
259
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
260 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
261 if (!e.message.startsWith('Cannot assign to read-only p')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
262 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
263 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
264 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
265
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
266 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
267
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
268 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
269 ['cache', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
270 const props = ['default', 'no-cache', 'no-store', 'reload',
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
271 'force-cache', 'only-if-cached', '#'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
272 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
273 props.forEach(cv => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
274 var r = new Request("http://nginx.org", {cache: cv});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
275 if (r.cache != cv) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
276 throw new Error(`r.cache != \${cv}`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
277 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
278 })
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
279
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
280 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
281 if (!e.message.startsWith('unknown cache type: #')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
282 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
283 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
284 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
285
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
286 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
287
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
288 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
289 ['credentials', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
290 const props = ['omit', 'include', 'same-origin', '#'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
291 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
292 props.forEach(cr => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
293 var r = new Request("http://nginx.org",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
294 {credentials: cr});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
295 if (r.credentials != cr) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
296 throw new Error(`r.credentials != \${cr}`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
297 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
298 })
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
299
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
300 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
301 if (!e.message.startsWith('unknown credentials type: #')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
302 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
303 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
304 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
305
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
306 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
307
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
308 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
309 ['method', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
310 const methods = ['get', 'hEad', 'Post', 'OPTIONS', 'PUT',
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
311 'DELETE', 'CONNECT'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
312 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
313 methods.forEach(m => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
314 var r = new Request("http://nginx.org", {method: m});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
315 if (r.method != m.toUpperCase()) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
316 throw new Error(`r.method != \${m}`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
317 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
318 })
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
319
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
320 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
321 if (!e.message.startsWith('forbidden method: CONNECT')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
322 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
323 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
324 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
325
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
326 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
327
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
328 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
329 ['mode', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
330 const props = ['same-origin', 'cors', 'no-cors', 'navigate',
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
331 'websocket', '#'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
332 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
333 props.forEach(m => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
334 var r = new Request("http://nginx.org", {mode: m});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
335 if (r.mode != m) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
336 throw new Error(`r.mode != \${m}`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
337 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
338 })
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
339
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
340 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
341 if (!e.message.startsWith('unknown mode type: #')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
342 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
343 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
344 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
345
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
346 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
347
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
348 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
349 ['inherit', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
350 var r = new Request("http://nginx.org",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
351 {headers: {a: 'X', b: 'Y'}});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
352 var r2 = new Request(r);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
353 r2.headers.append('a', 'Z')
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
354 return `\${r2.url}: \${r2.headers.get('a')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
355 }, 'http://nginx.org: X, Z'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
356 ['inherit2', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
357 var r = new Request("http://nginx.org",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
358 {headers: {a: 'X', b: 'Y'}});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
359 var r2 = new Request(r);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
360 r2.headers.append('a', 'Z')
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
361 return `\${r.url}: \${r.headers.get('a')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
362 }, 'http://nginx.org: X'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
363 ['inherit3', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
364 var h = new Headers();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
365 h.append('a', 'X');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
366 h.append('a', 'Z');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
367 var r = new Request("http://nginx.org", {headers: h});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
368 return `\${r.url}: \${r.headers.get('a')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
369 }, 'http://nginx.org: X, Z'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
370 ['content type', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
371 var r = new Request("http://nginx.org",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
372 {body: 'ABC', method: 'POST'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
373 var body = await r.text();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
374 return `\${body}: \${r.headers.get('Content-Type')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
375 }, 'ABC: text/plain;charset=UTF-8'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
376 ['GET body', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
377 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
378 var r = new Request("http://nginx.org", {body: 'ABC'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
379
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
380 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
381 if (!e.message.startsWith('Request body incompatible w')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
382 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
383 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
384 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
385
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
386 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
387
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
388 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
389 ];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
390
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
391 run(r, tests);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
392 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
393
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
394 async function response(r) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
395 const tests = [
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
396 ['empty', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
397 var r = new Response();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
398 var body = await r.text();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
399 return `\${r.url}: \${r.status} \${body} \${r.headers.get('a')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
400 }, ': 200 null'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
401 ['normal', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
402 var r = new Response("ABC", {headers: {a: 'X', b: 'Y'}});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
403 var body = await r.text();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
404 return `\${r.url}: \${r.status} \${body} \${r.headers.get('a')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
405 }, ': 200 ABC X'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
406 ['headers', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
407 var r = new Response(null,
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
408 {headers: new Headers({a: 'X', b: 'Y'})});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
409 var body = await r.text();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
410 return `\${r.url}: \${body} \${r.headers.get('b')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
411 }, ': Y'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
412 ['json', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
413 var r = new Response('{"a": {"b": 42}}');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
414 var json = await r.json();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
415 return json.a.b;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
416 }, 42],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
417 ['statusText', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
418 const statuses = ['status text', 'aa\\u0000a'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
419 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
420 statuses.forEach(s => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
421 var r = new Response(null, {statusText: s});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
422 if (r.statusText != s) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
423 throw new Error(`r.statusText != \${s}`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
424 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
425 })
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
426
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
427 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
428 if (!e.message.startsWith('invalid Response statusText')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
429 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
430 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
431 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
432
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
433 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
434
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
435 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
436 ];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
437
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
438 run(r, tests);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
439 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
440
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
441 async function fetch(r) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
442 const tests = [
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
443 ['method', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
444 var req = new Request("http://127.0.0.1:$p0/method",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
445 {method: 'PUT'});
1822
de6aeda5c274 Tests: removed excessive tab characters from js_fetch_objects.t.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1821
diff changeset
446 var r = await ngx.fetch(req);
de6aeda5c274 Tests: removed excessive tab characters from js_fetch_objects.t.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1821
diff changeset
447 var body = await r.text();
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
448 return `\${r.url}: \${r.status} \${body} \${r.headers.get('a')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
449 }, 'http://127.0.0.1:$p0/method: 200 PUT null'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
450 ['request body', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
451 var req = new Request("http://127.0.0.1:$p0/body",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
452 {body: 'foo'});
1822
de6aeda5c274 Tests: removed excessive tab characters from js_fetch_objects.t.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1821
diff changeset
453 var r = await ngx.fetch(req);
de6aeda5c274 Tests: removed excessive tab characters from js_fetch_objects.t.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1821
diff changeset
454 var body = await r.text();
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
455 return `\${r.url}: \${r.status} \${body}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
456 }, 'http://127.0.0.1:$p0/body: 201 foo'],
1821
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
457 ];
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
458
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
459 run(r, tests);
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
460 }
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
461
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
462 async function fetch_multi_header(r) {
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
463 const tests = [
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
464 ['request multi header', async () => {
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
465 var h = new Headers({a: 'X'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
466 h.append('a', 'Z');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
467 var req = new Request("http://127.0.0.1:$p0/header",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
468 {headers: h});
1821
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
469 var r = await ngx.fetch(req);
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
470 var body = await r.text();
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
471 return `\${r.url}: \${r.status} \${body}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
472 }, 'http://127.0.0.1:$p0/header: 200 X, Z'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
473 ];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
474
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
475 run(r, tests);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
476 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
477
1821
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
478 export default {njs: test_njs, body, headers, request, response, fetch,
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
479 fetch_multi_header};
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
480 EOF
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
481
1821
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
482 $t->try_run('no njs')->plan(5);
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
483
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
484 ###############################################################################
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
485
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
486 local $TODO = 'not yet' unless has_version('0.7.10');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
487
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
488 like(http_get('/headers'), qr/200 OK/s, 'headers tests');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
489 like(http_get('/request'), qr/200 OK/s, 'request tests');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
490 like(http_get('/response'), qr/200 OK/s, 'response tests');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
491 like(http_get('/fetch'), qr/200 OK/s, 'fetch tests');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
492
1821
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
493 TODO: {
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
494 local $TODO = 'not yet' unless $t->has_version('1.23.0');
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
495
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
496 like(http_get('/fetch_multi_header'), qr/200 OK/s,
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
497 'fetch multi header tests');
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
498
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
499 }
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
500
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
501 ###############################################################################
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
502
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
503 sub has_version {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
504 my $need = shift;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
505
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
506 http_get('/njs') =~ /^([.0-9]+)$/m;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
507
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
508 my @v = split(/\./, $1);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
509 my ($n, $v);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
510
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
511 for $n (split(/\./, $need)) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
512 $v = shift @v || 0;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
513 return 0 if $n > $v;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
514 return 1 if $v > $n;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
515 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
516
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
517 return 1;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
518 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
519
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
520 ###############################################################################