Mercurial > hg > nginx-tests
annotate js_fetch.t @ 1811:520fb74cce4c
Tests: improved njs version check to account multi digit versions.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Fri, 02 Dec 2022 17:46:22 -0800 |
parents | e1fd234baac0 |
children | f98884ad7700 |
rev | line source |
---|---|
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
2 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
3 # (C) Dmitry Volyntsev |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
5 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
6 # Tests for http njs module, fetch method. |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
7 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
9 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
11 use strict; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
12 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
14 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
15 use Socket qw/ CRLF /; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
16 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
18 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
21 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
23 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
26 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
27 eval { require JSON::PP; }; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
28 plan(skip_all => "JSON::PP not installed") if $@; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
29 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
30 my $t = Test::Nginx->new()->has(qw/http/) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
31 ->write_file_expand('nginx.conf', <<'EOF'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
32 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
33 %%TEST_GLOBALS%% |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
34 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
35 daemon off; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
36 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
37 events { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
38 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
39 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
40 http { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
41 %%TEST_GLOBALS_HTTP%% |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
42 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
43 js_import test.js; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
44 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
45 server { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
46 listen 127.0.0.1:8080; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
47 server_name localhost; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
48 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
49 location /njs { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
50 js_content test.njs; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
51 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
52 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
53 location /broken { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
54 js_content test.broken; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
55 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
56 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
57 location /broken_response { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
58 js_content test.broken_response; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
59 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
60 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
61 location /body { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
62 js_content test.body; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
63 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
64 |
1780
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
65 location /body_special { |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
66 js_content test.body_special; |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
67 } |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
68 |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
69 location /chain { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
70 js_content test.chain; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
71 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
72 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
73 location /chunked { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
74 js_content test.chunked; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
75 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
76 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
77 location /header { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
78 js_content test.header; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
79 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
80 |
1756
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
81 location /header_iter { |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
82 js_content test.header_iter; |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
83 } |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
84 |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
85 location /multi { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
86 js_content test.multi; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
87 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
88 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
89 location /property { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
90 js_content test.property; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
91 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
92 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
93 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
94 server { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
95 listen 127.0.0.1:8080; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
96 server_name aaa; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
97 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
98 location /loc { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
99 js_content test.loc; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
100 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
101 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
102 location /json { } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
103 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
104 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
105 server { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
106 listen 127.0.0.1:8080; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
107 server_name bbb; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
108 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
109 location /loc { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
110 js_content test.loc; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
111 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
112 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
113 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
114 server { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
115 listen 127.0.0.1:8081; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
116 server_name ccc; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
117 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
118 location /loc { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
119 js_content test.loc; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
120 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
121 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
122 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
123 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
124 EOF |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
125 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
126 my $p0 = port(8080); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
127 my $p1 = port(8081); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
128 my $p2 = port(8082); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
129 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
130 $t->write_file('json', '{"a":[1,2], "b":{"c":"FIELD"}}'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
131 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
132 $t->write_file('test.js', <<EOF); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
133 function test_njs(r) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
134 r.return(200, njs.version); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
135 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
136 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
137 function body(r) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
138 var loc = r.args.loc; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
139 var getter = r.args.getter; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
140 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
141 function query(obj) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
142 var path = r.args.path; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
143 var retval = (getter == 'arrayBuffer') ? Buffer.from(obj).toString() |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
144 : obj; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
145 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
146 if (path) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
147 retval = path.split('.').reduce((a, v) => a[v], obj); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
148 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
149 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
150 return JSON.stringify(retval); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
151 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
152 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
153 ngx.fetch(`http://127.0.0.1:$p0/\${loc}`, {headers: {Host: 'aaa'}}) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
154 .then(reply => reply[getter]()) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
155 .then(data => r.return(200, query(data))) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
156 .catch(e => r.return(501, e.message)) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
157 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
158 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
159 function property(r) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
160 var opts = {headers:{Host: 'aaa'}}; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
161 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
162 if (r.args.code) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
163 opts.headers.code = r.args.code; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
164 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
165 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
166 var p = ngx.fetch('http://127.0.0.1:$p0/loc', opts) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
167 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
168 if (r.args.readBody) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
169 p = p.then(rep => |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
170 rep.text().then(body => {rep.text = body; return rep;})) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
171 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
172 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
173 p.then(reply => r.return(200, reply[r.args.pr])) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
174 .catch(e => r.return(501, e.message)) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
175 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
176 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
177 function process_errors(r, tests) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
178 var results = []; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
179 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
180 tests.forEach(args => { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
181 ngx.fetch.apply(r, args) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
182 .then(reply => { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
183 r.return(400, '["unexpected then"]'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
184 }) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
185 .catch(e => { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
186 results.push(e.message); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
187 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
188 if (results.length == tests.length) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
189 results.sort(); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
190 r.return(200, JSON.stringify(results)); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
191 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
192 }) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
193 }) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
194 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
195 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
196 function broken(r) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
197 var tests = [ |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
198 ['http://127.0.0.1:1/loc'], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
199 ['http://127.0.0.1:80800/loc'], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
200 [Symbol.toStringTag], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
201 ]; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
202 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
203 return process_errors(r, tests); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
204 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
205 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
206 function broken_response(r) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
207 var tests = [ |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
208 ['http://127.0.0.1:$p2/status_line'], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
209 ['http://127.0.0.1:$p2/length'], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
210 ['http://127.0.0.1:$p2/header'], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
211 ['http://127.0.0.1:$p2/headers'], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
212 ['http://127.0.0.1:$p2/content_length'], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
213 ]; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
214 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
215 return process_errors(r, tests); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
216 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
217 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
218 function chain(r) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
219 var results = []; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
220 var reqs = [ |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
221 ['http://127.0.0.1:$p0/loc', {headers: {Host:'aaa'}}], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
222 ['http://127.0.0.1:$p0/loc', {headers: {Host:'bbb'}}], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
223 ]; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
224 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
225 function next(reply) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
226 if (reqs.length == 0) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
227 r.return(200, "SUCCESS"); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
228 return; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
229 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
230 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
231 ngx.fetch.apply(r, reqs.pop()) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
232 .then(next) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
233 .catch(e => r.return(400, e.message)) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
234 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
235 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
236 next(); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
237 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
238 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
239 function chunked(r) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
240 var results = []; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
241 var tests = [ |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
242 ['http://127.0.0.1:$p2/big', {max_response_body_size:128000}], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
243 ['http://127.0.0.1:$p2/big/ok', {max_response_body_size:128000}], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
244 ['http://127.0.0.1:$p2/chunked'], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
245 ['http://127.0.0.1:$p2/chunked/ok'], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
246 ['http://127.0.0.1:$p2/chunked/big', {max_response_body_size:128}], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
247 ['http://127.0.0.1:$p2/chunked/big'], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
248 ]; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
249 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
250 function collect(v) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
251 results.push(v); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
252 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
253 if (results.length == tests.length) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
254 results.sort(); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
255 r.return(200, JSON.stringify(results)); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
256 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
257 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
258 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
259 tests.forEach(args => { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
260 ngx.fetch.apply(r, args) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
261 .then(reply => reply.text()) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
262 .then(body => collect(body.length)) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
263 .catch(e => collect(e.message)) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
264 }) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
265 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
266 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
267 function header(r) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
268 var url = `http://127.0.0.1:$p2/\${r.args.loc}`; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
269 var method = r.args.method ? r.args.method : 'get'; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
270 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
271 var p = ngx.fetch(url) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
272 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
273 if (r.args.readBody) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
274 p = p.then(rep => |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
275 rep.text().then(body => {rep.text = body; return rep;})) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
276 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
277 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
278 p.then(reply => { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
279 var h = reply.headers[method](r.args.h); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
280 r.return(200, njs.dump(h)); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
281 }) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
282 .catch(e => r.return(501, e.message)) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
283 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
284 |
1780
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
285 async function body_special(r) { |
1796
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
286 let opts = {}; |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
287 |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
288 if (r.args.method) { |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
289 opts.method = r.args.method; |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
290 } |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
291 |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
292 let reply = await ngx.fetch(`http://127.0.0.1:$p2/\${r.args.loc}`, |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
293 opts); |
1780
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
294 let body = await reply.text(); |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
295 |
1796
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
296 r.return(200, body != '' ? body : '<empty>'); |
1780
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
297 } |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
298 |
1756
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
299 async function header_iter(r) { |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
300 let url = `http://127.0.0.1:$p2/\${r.args.loc}`; |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
301 |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
302 let response = await ngx.fetch(url); |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
303 |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
304 let headers = response.headers; |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
305 let out = []; |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
306 for (let key in response.headers) { |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
307 if (key != 'Connection') { |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
308 out.push(`\${key}:\${headers.get(key)}`); |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
309 } |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
310 } |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
311 |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
312 r.return(200, njs.dump(out)); |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
313 } |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
314 |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
315 function multi(r) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
316 var results = []; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
317 var tests = [ |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
318 [ |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
319 'http://127.0.0.1:$p0/loc', |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
320 { headers: {Code: 201, Host: 'aaa'}}, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
321 ], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
322 [ |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
323 'http://127.0.0.1:$p0/loc', |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
324 { method:'POST', headers: {Code: 401, Host: 'bbb'}, body: 'OK'}, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
325 ], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
326 [ |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
327 'http://127.0.0.1:$p1/loc', |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
328 { method:'PATCH', |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
329 headers: {foo:undefined, bar:'xxx', Host: 'ccc'}}, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
330 ], |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
331 ]; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
332 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
333 function cmp(a,b) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
334 if (a.b > b.b) {return 1;} |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
335 if (a.b < b.b) {return -1;} |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
336 return 0 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
337 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
338 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
339 tests.forEach(args => { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
340 ngx.fetch.apply(r, args) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
341 .then(rep => |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
342 rep.text().then(body => {rep.text = body; return rep;})) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
343 .then(rep => { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
344 results.push({b:rep.text, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
345 c:rep.status, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
346 u:rep.url}); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
347 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
348 if (results.length == tests.length) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
349 results.sort(cmp); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
350 r.return(200, JSON.stringify(results)); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
351 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
352 }) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
353 .catch(e => { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
354 r.return(400, `["\${e.message}"]`); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
355 throw e; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
356 }) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
357 }) |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
358 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
359 if (r.args.throw) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
360 throw 'Oops'; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
361 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
362 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
363 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
364 function str(v) { return v ? v : ''}; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
365 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
366 function loc(r) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
367 var v = r.variables; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
368 var body = str(r.requestText); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
369 var foo = str(r.headersIn.foo); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
370 var bar = str(r.headersIn.bar); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
371 var c = r.headersIn.code ? Number(r.headersIn.code) : 200; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
372 r.return(c, `\${v.host}:\${v.request_method}:\${foo}:\${bar}:\${body}`); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
373 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
374 |
1780
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
375 export default {njs: test_njs, body, broken, broken_response, body_special, |
1756
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
376 chain, chunked, header, header_iter, multi, loc, property}; |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
377 EOF |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
378 |
1796
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
379 $t->try_run('no njs.fetch')->plan(33); |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
380 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
381 $t->run_daemon(\&http_daemon, port(8082)); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
382 $t->waitforsocket('127.0.0.1:' . port(8082)); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
383 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
384 ############################################################################### |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
385 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
386 like(http_get('/body?getter=arrayBuffer&loc=loc'), qr/200 OK.*"aaa:GET:::"$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
387 'fetch body arrayBuffer'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
388 like(http_get('/body?getter=text&loc=loc'), qr/200 OK.*"aaa:GET:::"$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
389 'fetch body text'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
390 like(http_get('/body?getter=json&loc=json&path=b.c'), |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
391 qr/200 OK.*"FIELD"$/s, 'fetch body json'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
392 like(http_get('/body?getter=json&loc=loc'), qr/501/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
393 'fetch body json invalid'); |
1780
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
394 like(http_get('/body_special?loc=parted'), qr/200 OK.*X{32000}$/s, |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
395 'fetch body parted'); |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
396 like(http_get('/property?pr=bodyUsed'), qr/false$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
397 'fetch bodyUsed false'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
398 like(http_get('/property?pr=bodyUsed&readBody=1'), qr/true$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
399 'fetch bodyUsed true'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
400 like(http_get('/property?pr=ok'), qr/200 OK.*true$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
401 'fetch ok true'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
402 like(http_get('/property?pr=ok&code=401'), qr/200 OK.*false$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
403 'fetch ok false'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
404 like(http_get('/property?pr=redirected'), qr/200 OK.*false$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
405 'fetch redirected false'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
406 like(http_get('/property?pr=statusText'), qr/200 OK.*OK$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
407 'fetch statusText OK'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
408 like(http_get('/property?pr=statusText&code=403'), qr/200 OK.*Forbidden$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
409 'fetch statusText Forbidden'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
410 like(http_get('/property?pr=type'), qr/200 OK.*basic$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
411 'fetch type'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
412 like(http_get('/header?loc=duplicate_header&h=BAR'), qr/200 OK.*c$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
413 'fetch header'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
414 like(http_get('/header?loc=duplicate_header&h=BARR'), qr/200 OK.*null$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
415 'fetch no header'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
416 like(http_get('/header?loc=duplicate_header&h=foo'), qr/200 OK.*a,b$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
417 'fetch header duplicate'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
418 like(http_get('/header?loc=duplicate_header&h=BAR&method=getAll'), |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
419 qr/200 OK.*\['c']$/s, 'fetch getAll header'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
420 like(http_get('/header?loc=duplicate_header&h=BARR&method=getAll'), |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
421 qr/200 OK.*\[]$/s, 'fetch getAll no header'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
422 like(http_get('/header?loc=duplicate_header&h=FOO&method=getAll'), |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
423 qr/200 OK.*\['a','b']$/s, 'fetch getAll duplicate'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
424 like(http_get('/header?loc=duplicate_header&h=bar&method=has'), |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
425 qr/200 OK.*true$/s, 'fetch header has'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
426 like(http_get('/header?loc=duplicate_header&h=buz&method=has'), |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
427 qr/200 OK.*false$/s, 'fetch header does not have'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
428 like(http_get('/header?loc=chunked/big&h=BAR&readBody=1'), qr/200 OK.*xxx$/s, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
429 'fetch chunked header'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
430 is(get_json('/multi'), |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
431 '[{"b":"aaa:GET:::","c":201,"u":"http://127.0.0.1:'.$p0.'/loc"},' . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
432 '{"b":"bbb:POST:::OK","c":401,"u":"http://127.0.0.1:'.$p0.'/loc"},' . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
433 '{"b":"ccc:PATCH::xxx:","c":200,"u":"http://127.0.0.1:'.$p1.'/loc"}]', |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
434 'fetch multi'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
435 like(http_get('/multi?throw=1'), qr/500/s, 'fetch destructor'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
436 is(get_json('/broken'), |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
437 '[' . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
438 '"connect failed",' . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
439 '"failed to convert url arg",' . |
1727
bdefe70ae1a7
Tests: removed negative fetch API test for HTTPS schema.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1640
diff
changeset
|
440 '"invalid url"]', 'fetch broken'); |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
441 is(get_json('/broken_response'), |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
442 '["invalid fetch content length",' . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
443 '"invalid fetch header",' . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
444 '"invalid fetch status line",' . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
445 '"prematurely closed connection",' . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
446 '"prematurely closed connection"]', 'fetch broken response'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
447 is(get_json('/chunked'), |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
448 '[10,100010,25500,' . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
449 '"invalid fetch chunked response",' . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
450 '"prematurely closed connection",' . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
451 '"very large fetch chunked response"]', 'fetch chunked'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
452 like(http_get('/chain'), qr/200 OK.*SUCCESS$/s, 'fetch chain'); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
453 |
1756
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
454 TODO: { |
1758
7c727869aeda
Tests: skip unsafe large header test in js_fetch.t.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1756
diff
changeset
|
455 todo_skip 'leaves coredump', 1 unless $ENV{TEST_NGINX_UNSAFE} |
1811
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
456 or has_version('0.7.4'); |
1756
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
457 |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
458 like(http_get('/header_iter?loc=duplicate_header_large'), |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
459 qr/\['A:a','B:a','C:a','D:a','E:a','F:a','G:a','H:a','Foo:a,b']$/s, |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
460 'fetch header duplicate large'); |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
461 |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
462 } |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
463 |
1780
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
464 TODO: { |
1811
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
465 local $TODO = 'not yet' unless has_version('0.7.7'); |
1780
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
466 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
467 like(http_get('/body_special?loc=no_content_length'), |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
468 qr/200 OK.*CONTENT-BODY$/s, 'fetch body without content-length'); |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
469 like(http_get('/body_special?loc=no_content_length/parted'), |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
470 qr/200 OK.*X{32000}$/s, 'fetch body without content-length parted'); |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
471 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
472 } |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
473 |
1796
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
474 TODO: { |
1811
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
475 local $TODO = 'not yet' unless has_version('0.7.8'); |
1796
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
476 |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
477 like(http_get('/body_special?loc=head&method=HEAD'), |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
478 qr/200 OK.*<empty>$/s, 'fetch head method'); |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
479 like(http_get('/body_special?loc=length&method=head'), |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
480 qr/200 OK.*<empty>$/s, 'fetch head method lower case'); |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
481 |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
482 } |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
483 |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
484 ############################################################################### |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
485 |
1811
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
486 sub has_version { |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
487 my $need = shift; |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
488 |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
489 http_get('/njs') =~ /^([.0-9]+)$/m; |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
490 |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
491 my @v = split(/\./, $1); |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
492 my ($n, $v); |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
493 |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
494 for $n (split(/\./, $need)) { |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
495 $v = shift @v || 0; |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
496 return 0 if $n > $v; |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
497 return 1 if $v > $n; |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
498 } |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
499 |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
500 return 1; |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
501 } |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
502 |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
503 ############################################################################### |
520fb74cce4c
Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1796
diff
changeset
|
504 |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
505 sub recode { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
506 my $json; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
507 eval { $json = JSON::PP::decode_json(shift) }; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
508 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
509 if ($@) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
510 return "<failed to parse JSON>"; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
511 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
512 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
513 JSON::PP->new()->canonical()->encode($json); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
514 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
515 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
516 sub get_json { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
517 http_get(shift) =~ /\x0d\x0a?\x0d\x0a?(.*)/ms; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
518 recode($1); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
519 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
520 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
521 ############################################################################### |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
522 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
523 sub http_daemon { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
524 my $port = shift; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
525 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
526 my $server = IO::Socket::INET->new( |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
527 Proto => 'tcp', |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
528 LocalAddr => '127.0.0.1:' . $port, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
529 Listen => 5, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
530 Reuse => 1 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
531 ) or die "Can't create listening socket: $!\n"; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
532 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
533 local $SIG{PIPE} = 'IGNORE'; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
534 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
535 while (my $client = $server->accept()) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
536 $client->autoflush(1); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
537 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
538 my $headers = ''; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
539 my $uri = ''; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
540 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
541 while (<$client>) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
542 $headers .= $_; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
543 last if (/^\x0d?\x0a?$/); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
544 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
545 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
546 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
547 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
548 if ($uri eq '/status_line') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
549 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
550 "HTTP/1.1 2A"; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
551 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
552 } elsif ($uri eq '/content_length') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
553 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
554 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
555 "Content-Length: " . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
556 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
557 CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
558 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
559 } elsif ($uri eq '/header') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
560 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
561 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
562 "@#" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
563 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
564 CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
565 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
566 } elsif ($uri eq '/duplicate_header') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
567 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
568 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
569 "Foo: a" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
570 "bar: c" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
571 "Foo: b" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
572 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
573 CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
574 |
1756
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
575 } elsif ($uri eq '/duplicate_header_large') { |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
576 print $client |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
577 "HTTP/1.1 200 OK" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
578 "A: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
579 "B: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
580 "C: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
581 "D: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
582 "E: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
583 "F: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
584 "G: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
585 "H: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
586 "Foo: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
587 "Foo: b" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
588 "Connection: close" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
589 CRLF; |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
590 |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
591 } elsif ($uri eq '/headers') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
592 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
593 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
594 "Connection: close" . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
595 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
596 } elsif ($uri eq '/length') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
597 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
598 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
599 "Content-Length: 100" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
600 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
601 CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
602 "unfinished" . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
603 |
1796
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
604 } elsif ($uri eq '/head') { |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
605 print $client |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
606 "HTTP/1.1 200 OK" . CRLF . |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
607 "Content-Length: 100" . CRLF . |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
608 "Connection: close" . CRLF . |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
609 CRLF; |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
610 |
1780
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
611 } elsif ($uri eq '/parted') { |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
612 print $client |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
613 "HTTP/1.1 200 OK" . CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
614 "Content-Length: 32000" . CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
615 "Connection: close" . CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
616 CRLF; |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
617 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
618 for (1 .. 4) { |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
619 select undef, undef, undef, 0.01; |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
620 print $client "X" x 8000; |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
621 } |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
622 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
623 } elsif ($uri eq '/no_content_length') { |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
624 print $client |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
625 "HTTP/1.1 200 OK" . CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
626 "Connection: close" . CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
627 CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
628 "CONTENT-BODY"; |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
629 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
630 } elsif ($uri eq '/no_content_length/parted') { |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
631 print $client |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
632 "HTTP/1.1 200 OK" . CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
633 "Connection: close" . CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
634 CRLF; |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
635 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
636 for (1 .. 4) { |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
637 select undef, undef, undef, 0.01; |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
638 print $client "X" x 8000; |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
639 } |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
640 |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
641 } elsif ($uri eq '/big') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
642 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
643 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
644 "Content-Length: 100100" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
645 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
646 CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
647 for (1 .. 1000) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
648 print $client ("X" x 98) . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
649 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
650 print $client "unfinished" . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
651 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
652 } elsif ($uri eq '/big/ok') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
653 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
654 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
655 "Content-Length: 100010" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
656 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
657 CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
658 for (1 .. 1000) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
659 print $client ("X" x 98) . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
660 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
661 print $client "finished" . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
662 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
663 } elsif ($uri eq '/chunked') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
664 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
665 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
666 "Transfer-Encoding: chunked" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
667 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
668 CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
669 "ff" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
670 "unfinished" . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
671 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
672 } elsif ($uri eq '/chunked/ok') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
673 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
674 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
675 "Transfer-Encoding: chunked" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
676 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
677 CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
678 "a" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
679 "finished" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
680 CRLF . "0" . CRLF . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
681 } elsif ($uri eq '/chunked/big') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
682 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
683 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
684 "Transfer-Encoding: chunked" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
685 "Bar: xxx" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
686 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
687 CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
688 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
689 for (1 .. 100) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
690 print $client "ff" . CRLF . ("X" x 255) . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
691 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
692 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
693 print $client "0" . CRLF . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
694 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
695 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
696 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
697 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
698 ############################################################################### |