annotate js_fetch_objects.t @ 1822:de6aeda5c274

Tests: removed excessive tab characters from js_fetch_objects.t.
author Dmitry Volyntsev <xeioex@nginx.com>
date Mon, 06 Feb 2023 09:36:14 -0800
parents 1792ba2e8026
children 0152ce2de27f
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 ['forbidden header', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
162 const forbidden = ['Host', 'Connection', 'Content-length'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
163 forbidden.forEach(fh => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
164 var headers = {};
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
165 headers[fh] = 'xxx';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
166 headers.foo = 'bar';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
167
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
168 var h = new Headers(headers);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
169 if (h.get(fh) != 'xxx') {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
170 throw new Error(`forbidden header \${fh}`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
171 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
172
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
173 if (h.get('foo') != 'bar') {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
174 throw new Error(
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
175 `non forbidden header foo: \${h.get('foo')}`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
176 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
177 })
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
178
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
179 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
180
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
181 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
182 ['combine', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
183 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
184 return h.get('a');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
185 }, 'X, Z'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
186 ['combine2', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
187 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
188 return h.get('a');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
189 }, 'x, z'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
190 ['combine3', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
191 var h = new Headers();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
192 h.append('a', 'A');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
193 h.append('a', 'B');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
194 h.append('a', 'C');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
195 h.append('a', 'D');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
196 h.append('a', 'E');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
197 h.append('a', 'F');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
198 return h.get('a');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
199 }, 'A, B, C, D, E, F'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
200 ['getAll', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
201 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
202 return njs.dump(h.getAll('a'));
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
203 }, "['X','Z']"],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
204 ['inherit', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
205 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
206 var h2 = new Headers(h);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
207 h2.append('c', 'Z');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
208 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
209 }, true],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
210 ['delete', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
211 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
212 h.delete('b');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
213 return h.get('a') && !h.get('b');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
214 }, true],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
215 ['forEach', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
216 var r = [];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
217 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
218 h.delete('b');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
219 h.append('z', '3');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
220 h.append('a', '4');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
221 h.append('q', '5');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
222 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
223 return r.join('|');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
224 }, '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
225 ['set', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
226 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
227 h.set('a', '#');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
228 return h.get('a');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
229 }, '#'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
230 ];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
231
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
232 run(r, tests);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
233 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
234
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
235 async function request(r) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
236 const tests = [
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
237 ['empty', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
238 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
239 new Request();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
240 throw new Error(`Request() should throw`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
241
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
242 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
243 if (e.message != '1st argument is required') {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
244 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
245 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
246 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
247
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
248 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
249
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
250 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
251 ['normal', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
252 var r = new Request("http://nginx.org",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
253 {headers: {a: 'X', b: 'Y'}});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
254 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
255 }, 'http://nginx.org: GET X'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
256 ['url trim', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
257 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
258 + "\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\x0f"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
259 + "\\x10\\x11\\x12\\x13\\x14\\x15\\x16"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
260 + "\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
261 + "\\x1e\\x1f\\x20http://nginx.org\\x00"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
262 + "\\x01\\x02\\x03\\x05\\x06\\x07\\x08"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
263 + "\\x09\\x0a\\x0b\\x0c\\x0d\\x0e\\x0f"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
264 + "\\x10\\x11\\x12\\x13\\x14\\x15\\x16"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
265 + "\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d"
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
266 + "\\x1e\\x1f\\x20");
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
267 return r.url;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
268 }, 'http://nginx.org'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
269 ['read only', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
270 var r = new Request("http://nginx.org");
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
271
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
272 const props = ['bodyUsed', 'cache', 'credentials', 'headers',
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
273 'method', 'mode', 'url'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
274 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
275 props.forEach(prop => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
276 r[prop] = 1;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
277 throw new Error(
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
278 `setting read-only \${prop} should throw`);
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
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
281 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
282 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
283 throw e;
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
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
287 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
288
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
289 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
290 ['cache', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
291 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
292 'force-cache', 'only-if-cached', '#'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
293 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
294 props.forEach(cv => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
295 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
296 if (r.cache != cv) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
297 throw new Error(`r.cache != \${cv}`);
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
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
301 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
302 if (!e.message.startsWith('unknown cache type: #')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
303 throw e;
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
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
307 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
308
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
309 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
310 ['credentials', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
311 const props = ['omit', 'include', 'same-origin', '#'];
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 props.forEach(cr => {
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",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
315 {credentials: cr});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
316 if (r.credentials != cr) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
317 throw new Error(`r.credentials != \${cr}`);
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
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
321 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
322 if (!e.message.startsWith('unknown credentials type: #')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
323 throw e;
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
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
327 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
328
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
329 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
330 ['forbidden request header', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
331 const forbidden = ['Host', 'Connection', 'Content-length'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
332 forbidden.forEach(fh => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
333 var r = new Request("http://nginx.org",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
334 {headers: {[fh]: 'xxx', foo: 'bar'}});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
335 if (r.headers.get(fh) != null) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
336 throw new Error(`forbidden header \${fh}`);
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 if (r.headers.get('foo') != 'bar') {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
340 throw new Error(
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
341 `non forbidden header foo: \${r.headers.get('foo')}`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
342 }
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 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
346
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
347 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
348 ['method', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
349 const methods = ['get', 'hEad', 'Post', 'OPTIONS', 'PUT',
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
350 'DELETE', 'CONNECT'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
351 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
352 methods.forEach(m => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
353 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
354 if (r.method != m.toUpperCase()) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
355 throw new Error(`r.method != \${m}`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
356 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
357 })
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
358
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
359 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
360 if (!e.message.startsWith('forbidden method: CONNECT')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
361 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
362 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
363 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
364
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
365 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
366
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
367 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
368 ['mode', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
369 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
370 'websocket', '#'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
371 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
372 props.forEach(m => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
373 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
374 if (r.mode != m) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
375 throw new Error(`r.mode != \${m}`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
376 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
377 })
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
378
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
379 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
380 if (!e.message.startsWith('unknown mode type: #')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
381 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
382 }
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 return 'OK';
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
386
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
387 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
388 ['inherit', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
389 var r = new Request("http://nginx.org",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
390 {headers: {a: 'X', b: 'Y'}});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
391 var r2 = new Request(r);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
392 r2.headers.append('a', 'Z')
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
393 return `\${r2.url}: \${r2.headers.get('a')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
394 }, 'http://nginx.org: X, Z'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
395 ['inherit2', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
396 var r = new Request("http://nginx.org",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
397 {headers: {a: 'X', b: 'Y'}});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
398 var r2 = new Request(r);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
399 r2.headers.append('a', 'Z')
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
400 return `\${r.url}: \${r.headers.get('a')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
401 }, 'http://nginx.org: X'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
402 ['inherit3', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
403 var h = new Headers();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
404 h.append('a', 'X');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
405 h.append('a', 'Z');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
406 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
407 return `\${r.url}: \${r.headers.get('a')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
408 }, 'http://nginx.org: X, Z'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
409 ['content type', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
410 var r = new Request("http://nginx.org",
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
411 {body: 'ABC', method: 'POST'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
412 var body = await r.text();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
413 return `\${body}: \${r.headers.get('Content-Type')}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
414 }, 'ABC: text/plain;charset=UTF-8'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
415 ['GET body', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
416 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
417 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
418
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
419 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
420 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
421 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
422 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
423 }
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 return 'OK';
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 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
428 ];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
429
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
430 run(r, tests);
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 async function response(r) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
434 const tests = [
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
435 ['empty', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
436 var r = new Response();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
437 var body = await r.text();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
438 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
439 }, ': 200 null'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
440 ['normal', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
441 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
442 var body = await r.text();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
443 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
444 }, ': 200 ABC X'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
445 ['headers', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
446 var r = new Response(null,
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
447 {headers: new Headers({a: 'X', b: 'Y'})});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
448 var body = await r.text();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
449 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
450 }, ': Y'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
451 ['json', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
452 var r = new Response('{"a": {"b": 42}}');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
453 var json = await r.json();
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
454 return json.a.b;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
455 }, 42],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
456 ['statusText', () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
457 const statuses = ['status text', 'aa\\u0000a'];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
458 try {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
459 statuses.forEach(s => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
460 var r = new Response(null, {statusText: s});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
461 if (r.statusText != s) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
462 throw new Error(`r.statusText != \${s}`);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
463 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
464 })
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
465
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
466 } catch (e) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
467 if (!e.message.startsWith('invalid Response statusText')) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
468 throw e;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
469 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
470 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
471
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
472 return 'OK';
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 }, 'OK'],
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
475 ];
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 run(r, tests);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
478 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
479
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
480 async function fetch(r) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
481 const tests = [
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
482 ['method', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
483 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
484 {method: 'PUT'});
1822
de6aeda5c274 Tests: removed excessive tab characters from js_fetch_objects.t.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1821
diff changeset
485 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
486 var body = await r.text();
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
487 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
488 }, '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
489 ['request body', async () => {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
490 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
491 {body: 'foo'});
1822
de6aeda5c274 Tests: removed excessive tab characters from js_fetch_objects.t.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1821
diff changeset
492 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
493 var body = await r.text();
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
494 return `\${r.url}: \${r.status} \${body}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
495 }, '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
496 ];
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
497
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
498 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
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
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
501 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
502 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
503 ['request multi header', async () => {
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
504 var h = new Headers({a: 'X'});
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
505 h.append('a', 'Z');
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
506 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
507 {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
508 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
509 var body = await r.text();
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
510 return `\${r.url}: \${r.status} \${body}`;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
511 }, '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
512 ];
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
513
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
514 run(r, tests);
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
1821
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
517 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
518 fetch_multi_header};
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
519 EOF
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
520
1821
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
521 $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
522
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
523 ###############################################################################
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
524
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
525 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
526
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
527 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
528 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
529 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
530 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
531
1821
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
532 TODO: {
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
533 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
534
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
535 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
536 '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
537
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
538 }
1792ba2e8026 Tests: fixed js tests for Fetch API for nginx-1.22 and below.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1814
diff changeset
539
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
540 ###############################################################################
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
541
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
542 sub has_version {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
543 my $need = shift;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
544
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
545 http_get('/njs') =~ /^([.0-9]+)$/m;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
546
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
547 my @v = split(/\./, $1);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
548 my ($n, $v);
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
549
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
550 for $n (split(/\./, $need)) {
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
551 $v = shift @v || 0;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
552 return 0 if $n > $v;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
553 return 1 if $v > $n;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
554 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
555
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
556 return 1;
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
557 }
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
558
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
559 ###############################################################################