Mercurial > hg > nginx-tests
annotate js_fetch.t @ 1799:29f4d48b5b31
Tests: proxy_ssl_certificate inheritance test with empty value.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 13 Oct 2022 20:29:39 +0400 |
parents | e1fd234baac0 |
children | 520fb74cce4c |
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} |
7c727869aeda
Tests: skip unsafe large header test in js_fetch.t.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1756
diff
changeset
|
456 or http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '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: { |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
465 local $TODO = 'not yet' |
1783
95ba1e704b7b
Tests: fixed version check for tests added in bd21a4a7c9f5.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1780
diff
changeset
|
466 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.7'; |
1780
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
467 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
468 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
|
469 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
|
470 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
|
471 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
|
472 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
473 } |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
474 |
1796
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
475 TODO: { |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
476 local $TODO = 'not yet' |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
477 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.8'; |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
478 |
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=head&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'); |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
481 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
|
482 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
|
483 |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
484 } |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
485 |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
486 ############################################################################### |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
487 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
488 sub recode { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
489 my $json; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
490 eval { $json = JSON::PP::decode_json(shift) }; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
491 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
492 if ($@) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
493 return "<failed to parse JSON>"; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
494 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
495 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
496 JSON::PP->new()->canonical()->encode($json); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
497 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
498 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
499 sub get_json { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
500 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
|
501 recode($1); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
502 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
503 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
504 ############################################################################### |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
505 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
506 sub http_daemon { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
507 my $port = 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 my $server = IO::Socket::INET->new( |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
510 Proto => 'tcp', |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
511 LocalAddr => '127.0.0.1:' . $port, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
512 Listen => 5, |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
513 Reuse => 1 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
514 ) 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
|
515 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
516 local $SIG{PIPE} = 'IGNORE'; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
517 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
518 while (my $client = $server->accept()) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
519 $client->autoflush(1); |
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 my $headers = ''; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
522 my $uri = ''; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
523 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
524 while (<$client>) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
525 $headers .= $_; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
526 last if (/^\x0d?\x0a?$/); |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
527 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
528 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
529 $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
|
530 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
531 if ($uri eq '/status_line') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
532 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
533 "HTTP/1.1 2A"; |
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 } elsif ($uri eq '/content_length') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
536 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
537 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
538 "Content-Length: " . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
539 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
540 CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
541 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
542 } elsif ($uri eq '/header') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
543 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
544 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
545 "@#" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
546 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
547 CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
548 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
549 } elsif ($uri eq '/duplicate_header') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
550 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
551 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
552 "Foo: a" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
553 "bar: c" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
554 "Foo: b" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
555 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
556 CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
557 |
1756
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
558 } 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
|
559 print $client |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
560 "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
|
561 "A: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
562 "B: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
563 "C: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
564 "D: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
565 "E: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
566 "F: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
567 "G: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
568 "H: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
569 "Foo: a" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
570 "Foo: b" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
571 "Connection: close" . CRLF . |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
572 CRLF; |
6966f099068d
Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1727
diff
changeset
|
573 |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
574 } elsif ($uri eq '/headers') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
575 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
576 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
577 "Connection: close" . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
578 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
579 } elsif ($uri eq '/length') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
580 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
581 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
582 "Content-Length: 100" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
583 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
584 CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
585 "unfinished" . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
586 |
1796
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
587 } elsif ($uri eq '/head') { |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
588 print $client |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
589 "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
|
590 "Content-Length: 100" . CRLF . |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
591 "Connection: close" . CRLF . |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
592 CRLF; |
e1fd234baac0
Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1783
diff
changeset
|
593 |
1780
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
594 } elsif ($uri eq '/parted') { |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
595 print $client |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
596 "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
|
597 "Content-Length: 32000" . CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
598 "Connection: close" . CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
599 CRLF; |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
600 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
601 for (1 .. 4) { |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
602 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
|
603 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
|
604 } |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
605 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
606 } 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
|
607 print $client |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
608 "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
|
609 "Connection: close" . CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
610 CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
611 "CONTENT-BODY"; |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
612 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
613 } 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
|
614 print $client |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
615 "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
|
616 "Connection: close" . CRLF . |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
617 CRLF; |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
618 |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
619 for (1 .. 4) { |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
620 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
|
621 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
|
622 } |
bd21a4a7c9f5
Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1758
diff
changeset
|
623 |
1640
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
624 } elsif ($uri eq '/big') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
625 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
626 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
627 "Content-Length: 100100" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
628 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
629 CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
630 for (1 .. 1000) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
631 print $client ("X" x 98) . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
632 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
633 print $client "unfinished" . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
634 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
635 } elsif ($uri eq '/big/ok') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
636 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
637 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
638 "Content-Length: 100010" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
639 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
640 CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
641 for (1 .. 1000) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
642 print $client ("X" x 98) . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
643 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
644 print $client "finished" . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
645 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
646 } elsif ($uri eq '/chunked') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
647 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
648 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
649 "Transfer-Encoding: chunked" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
650 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
651 CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
652 "ff" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
653 "unfinished" . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
654 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
655 } elsif ($uri eq '/chunked/ok') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
656 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
657 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
658 "Transfer-Encoding: chunked" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
659 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
660 CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
661 "a" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
662 "finished" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
663 CRLF . "0" . CRLF . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
664 } elsif ($uri eq '/chunked/big') { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
665 print $client |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
666 "HTTP/1.1 200 OK" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
667 "Transfer-Encoding: chunked" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
668 "Bar: xxx" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
669 "Connection: close" . CRLF . |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
670 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 for (1 .. 100) { |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
673 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
|
674 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
675 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
676 print $client "0" . CRLF . CRLF; |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
677 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
678 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
679 } |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
680 |
67adc5fd0548
Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
681 ############################################################################### |