annotate js_fetch.t @ 1851:0351dee227a8

Tests: unbreak tests with dynamic certificates on stable. In 74cffa9d4c43, ticket based session reuse is enabled in addition to using a shared SSL session cache. This changed how a session can be resumed in a different server: - for a session ID based resumption, it is resumed in the same context - when using session tickets, a key name is also checked for matching - with a ticket callback, this is skipped in favor of callback's logic This makes 'session id context match' tests fail with session tickets on stable since ticket key names are unique in distinct SSL contexts. On the other hand, tests pass on 1.23.2+ due to automatic ticket keys rotation that installs ticket callback, and using a common shared SSL session cache.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 28 Mar 2023 01:36:32 +0400
parents 1d88487eafbf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1813
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
73 location /chunked_ok {
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
74 js_content test.chunked_ok;
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
75 }
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
76
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
77 location /chunked_fail {
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
78 js_content test.chunked_fail;
1640
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
81 location /header {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
82 js_content test.header;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
83 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
84
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
85 location /header_iter {
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
86 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
87 }
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
88
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
89 location /multi {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
90 js_content test.multi;
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 location /property {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
94 js_content test.property;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
95 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
96
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
97 location /loc {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
98 js_content test.loc;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
99 }
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 location /json { }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
102 }
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 server {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
105 listen 127.0.0.1:8081;
1812
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
106 server_name localhost;
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
107
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
108 location /loc {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
109 js_content test.loc;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
110 }
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 EOF
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
115
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
116 my $p0 = port(8080);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
117 my $p1 = port(8081);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
118 my $p2 = port(8082);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
119
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
120 $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
121
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
122 $t->write_file('test.js', <<EOF);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
123 function test_njs(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
124 r.return(200, njs.version);
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
127 function body(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
128 var loc = r.args.loc;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
129 var getter = r.args.getter;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
130
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
131 function query(obj) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
132 var path = r.args.path;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
133 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
134 : obj;
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 if (path) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
137 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
138 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
139
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
140 return JSON.stringify(retval);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
141 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
142
1812
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
143 ngx.fetch(`http://127.0.0.1:$p0/\${loc}`)
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
144 .then(reply => reply[getter]())
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
145 .then(data => r.return(200, query(data)))
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
146 .catch(e => r.return(501, e.message))
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
147 }
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 function property(r) {
1812
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
150 var opts = {headers:{}};
1640
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 if (r.args.code) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
153 opts.headers.code = r.args.code;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
154 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
155
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
156 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
157
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
158 if (r.args.readBody) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
159 p = p.then(rep =>
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
160 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
161 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
162
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
163 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
164 .catch(e => r.return(501, e.message))
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
167 function process_errors(r, tests) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
168 var results = [];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
169
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
170 tests.forEach(args => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
171 ngx.fetch.apply(r, args)
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
172 .then(reply => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
173 r.return(400, '["unexpected then"]');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
174 })
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
175 .catch(e => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
176 results.push(e.message);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
177
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
178 if (results.length == tests.length) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
179 results.sort();
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
180 r.return(200, JSON.stringify(results));
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
181 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
182 })
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
183 })
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
186 function broken(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
187 var tests = [
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
188 ['http://127.0.0.1:1/loc'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
189 ['http://127.0.0.1:80800/loc'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
190 [Symbol.toStringTag],
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 return process_errors(r, tests);
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_response(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:$p2/status_line'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
199 ['http://127.0.0.1:$p2/length'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
200 ['http://127.0.0.1:$p2/header'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
201 ['http://127.0.0.1:$p2/headers'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
202 ['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
203 ];
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 return process_errors(r, tests);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
206 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
207
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
208 function chain(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
209 var results = [];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
210 var reqs = [
1812
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
211 ['http://127.0.0.1:$p0/loc'],
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
212 ['http://127.0.0.1:$p1/loc'],
1640
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 function next(reply) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
216 if (reqs.length == 0) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
217 r.return(200, "SUCCESS");
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
218 return;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
219 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
220
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
221 ngx.fetch.apply(r, reqs.pop())
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
222 .then(next)
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
223 .catch(e => r.return(400, e.message))
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
226 next();
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
227 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
228
1813
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
229 function chunked_ok(r) {
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
230 var results = [];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
231 var tests = [
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
232 ['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
233 ['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
234 ['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
235 ];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
236
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
237 function collect(v) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
238 results.push(v);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
239
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
240 if (results.length == tests.length) {
1813
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
241 r.return(200);
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
242 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
243 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
244
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
245 tests.forEach(args => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
246 ngx.fetch.apply(r, args)
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
247 .then(reply => reply.text())
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
248 .then(body => collect(body.length))
1813
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
249 })
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
250 }
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
251
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
252 function chunked_fail(r) {
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
253 var results = [];
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
254 var tests = [
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
255 ['http://127.0.0.1:$p2/big', {max_response_body_size:128000}],
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
256 ['http://127.0.0.1:$p2/chunked'],
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
257 ['http://127.0.0.1:$p2/chunked/big', {max_response_body_size:128}],
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
258 ];
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
259
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
260 function collect(v) {
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
261 results.push(v);
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
262
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
263 if (results.length == tests.length) {
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
264 r.return(200);
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
265 }
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
266 }
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
267
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
268 tests.forEach(args => {
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
269 ngx.fetch.apply(r, args)
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
270 .then(reply => reply.text())
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
271 .catch(e => collect(e.message))
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 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
274
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
275 function header(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
276 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
277 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
278
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
279 var p = ngx.fetch(url)
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
280
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
281 if (r.args.readBody) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
282 p = p.then(rep =>
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
283 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
284 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
285
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
286 p.then(reply => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
287 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
288 r.return(200, njs.dump(h));
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
289 })
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
290 .catch(e => r.return(501, e.message))
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
291 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
292
1780
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
293 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
294 let opts = {};
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
295
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
296 if (r.args.method) {
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
297 opts.method = r.args.method;
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
298 }
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
299
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
300 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
301 opts);
1780
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
302 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
303
1796
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
304 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
305 }
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
306
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
307 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
308 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
309
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
310 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
311
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
312 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
313 let out = [];
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
314 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
315 if (key != 'Connection') {
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
316 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
317 }
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
318 }
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
319
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
320 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
321 }
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
322
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
323 function multi(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
324 var results = [];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
325 var tests = [
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:$p0/loc',
1812
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
328 { headers: {Code: 201}},
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
329 ],
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 'http://127.0.0.1:$p0/loc',
1812
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
332 { method:'POST', headers: {Code: 401}, body: 'OK'},
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
333 ],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
334 [
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
335 'http://127.0.0.1:$p1/loc',
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
336 { method:'PATCH',
1812
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
337 headers: {bar:'xxx'}},
1640
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 ];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
340
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
341 function cmp(a,b) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
342 if (a.b > b.b) {return 1;}
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
343 if (a.b < b.b) {return -1;}
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
344 return 0
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
345 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
346
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
347 tests.forEach(args => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
348 ngx.fetch.apply(r, args)
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
349 .then(rep =>
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
350 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
351 .then(rep => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
352 results.push({b:rep.text,
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
353 c:rep.status,
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
354 u:rep.url});
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
355
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
356 if (results.length == tests.length) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
357 results.sort(cmp);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
358 r.return(200, JSON.stringify(results));
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
359 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
360 })
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
361 .catch(e => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
362 r.return(400, `["\${e.message}"]`);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
363 throw e;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
364 })
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
367 if (r.args.throw) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
368 throw 'Oops';
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
369 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
370 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
371
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
372 function str(v) { return v ? v : ''};
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 function loc(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
375 var v = r.variables;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
376 var body = str(r.requestText);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
377 var bar = str(r.headersIn.bar);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
378 var c = r.headersIn.code ? Number(r.headersIn.code) : 200;
1812
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
379 r.return(c, `\${v.request_method}:\${bar}:\${body}`);
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
1780
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
382 export default {njs: test_njs, body, broken, broken_response, body_special,
1813
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
383 chain, chunked_ok, chunked_fail, header, header_iter,
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
384 multi, loc, property};
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
385 EOF
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
386
1813
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
387 $t->try_run('no njs.fetch')->plan(34);
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
388
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
389 $t->run_daemon(\&http_daemon, port(8082));
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
390 $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
391
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
392 ###############################################################################
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
393
1812
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
394 like(http_get('/body?getter=arrayBuffer&loc=loc'), qr/200 OK.*"GET::"$/s,
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
395 'fetch body arrayBuffer');
1812
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
396 like(http_get('/body?getter=text&loc=loc'), qr/200 OK.*"GET::"$/s,
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
397 'fetch body text');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
398 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
399 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
400 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
401 '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
402 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
403 'fetch body parted');
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
404 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
405 'fetch bodyUsed false');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
406 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
407 'fetch bodyUsed true');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
408 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
409 'fetch ok true');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
410 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
411 'fetch ok false');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
412 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
413 'fetch redirected false');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
414 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
415 'fetch statusText OK');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
416 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
417 'fetch statusText Forbidden');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
418 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
419 'fetch type');
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=BAR'), qr/200 OK.*c$/s,
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
421 'fetch 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=BARR'), qr/200 OK.*null$/s,
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
423 'fetch no header');
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1813
diff changeset
424 like(http_get('/header?loc=duplicate_header&h=foo'), qr/200 OK.*a, ?b$/s,
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
425 'fetch header duplicate');
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=BAR&method=getAll'),
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
427 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
428 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
429 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
430 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
431 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
432 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
433 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
434 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
435 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
436 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
437 'fetch chunked header');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
438 is(get_json('/multi'),
1812
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
439 '[{"b":"GET::","c":201,"u":"http://127.0.0.1:'.$p0.'/loc"},' .
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
440 '{"b":"PATCH:xxx:","c":200,"u":"http://127.0.0.1:'.$p1.'/loc"},' .
f98884ad7700 Test: avoiding forbidden Host header in js fetch tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1811
diff changeset
441 '{"b":"POST::OK","c":401,"u":"http://127.0.0.1:'.$p0.'/loc"}]',
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
442 'fetch multi');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
443 like(http_get('/multi?throw=1'), qr/500/s, 'fetch destructor');
1813
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
444 like(http_get('/broken'), qr/200/s, 'fetch broken');
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
445 like(http_get('/broken_response'), qr/200/s, 'fetch broken response');
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
446 like(http_get('/chunked_ok'), qr/200/s, 'fetch chunked ok');
0a489a9abc7a Tests: improved fetch tests by avoding match for specific messages.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1812
diff changeset
447 like(http_get('/chunked_fail'), qr/200/s, 'fetch chunked fail');
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
448 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
449
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
450 TODO: {
1758
7c727869aeda Tests: skip unsafe large header test in js_fetch.t.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1756
diff changeset
451 todo_skip 'leaves coredump', 1 unless $ENV{TEST_NGINX_UNSAFE}
1811
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
452 or has_version('0.7.4');
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
453
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
454 like(http_get('/header_iter?loc=duplicate_header_large'),
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1813
diff changeset
455 qr/\['A:a','B:a','C:a','D:a','E:a','F:a','G:a','H:a','Moo:a, ?b']$/s,
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
456 '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
457
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
458 }
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
459
1780
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
460 TODO: {
1811
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
461 local $TODO = 'not yet' unless has_version('0.7.7');
1780
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
462
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
463 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
464 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
465 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
466 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
467
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
468 }
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
469
1796
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
470 TODO: {
1811
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
471 local $TODO = 'not yet' unless has_version('0.7.8');
1796
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
472
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
473 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
474 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
475 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
476 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
477
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
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
480 ###############################################################################
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
481
1811
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
482 sub has_version {
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
483 my $need = shift;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
484
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
485 http_get('/njs') =~ /^([.0-9]+)$/m;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
486
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
487 my @v = split(/\./, $1);
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
488 my ($n, $v);
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
489
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
490 for $n (split(/\./, $need)) {
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
491 $v = shift @v || 0;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
492 return 0 if $n > $v;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
493 return 1 if $v > $n;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
494 }
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
495
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
496 return 1;
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
497 }
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
498
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
499 ###############################################################################
520fb74cce4c Tests: improved njs version check to account multi digit versions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1796
diff changeset
500
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
501 sub recode {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
502 my $json;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
503 eval { $json = JSON::PP::decode_json(shift) };
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 if ($@) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
506 return "<failed to parse JSON>";
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
507 }
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 JSON::PP->new()->canonical()->encode($json);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
510 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
511
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
512 sub get_json {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
513 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
514 recode($1);
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
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
519 sub http_daemon {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
520 my $port = shift;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
521
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
522 my $server = IO::Socket::INET->new(
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
523 Proto => 'tcp',
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
524 LocalAddr => '127.0.0.1:' . $port,
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
525 Listen => 5,
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
526 Reuse => 1
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
527 ) 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
528
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
529 local $SIG{PIPE} = 'IGNORE';
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 while (my $client = $server->accept()) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
532 $client->autoflush(1);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
533
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
534 my $headers = '';
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
535 my $uri = '';
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
536
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
537 while (<$client>) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
538 $headers .= $_;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
539 last if (/^\x0d?\x0a?$/);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
540 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
541
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
542 $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
543
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
544 if ($uri eq '/status_line') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
545 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
546 "HTTP/1.1 2A";
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
547
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
548 } elsif ($uri eq '/content_length') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
549 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
550 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
551 "Content-Length: " . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
552 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
553 CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
554
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
555 } elsif ($uri eq '/header') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
556 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
557 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
558 "@#" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
559 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
560 CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
561
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
562 } elsif ($uri eq '/duplicate_header') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
563 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
564 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
565 "Foo: a" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
566 "bar: c" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
567 "Foo: b" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
568 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
569 CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
570
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
571 } 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
572 print $client
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
573 "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
574 "A: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
575 "B: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
576 "C: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
577 "D: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
578 "E: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
579 "F: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
580 "G: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
581 "H: a" . CRLF .
1814
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1813
diff changeset
582 "Moo: a" . CRLF .
1d88487eafbf Tests: added js tests for Fetch API objects.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1813
diff changeset
583 "Moo: b" . CRLF .
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
584 "Connection: close" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
585 CRLF;
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
586
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
587 } elsif ($uri eq '/headers') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
588 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
589 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
590 "Connection: close" . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
591
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
592 } elsif ($uri eq '/length') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
593 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
594 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
595 "Content-Length: 100" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
596 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
597 CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
598 "unfinished" . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
599
1796
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
600 } elsif ($uri eq '/head') {
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
601 print $client
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
602 "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
603 "Content-Length: 100" . CRLF .
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
604 "Connection: close" . CRLF .
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
605 CRLF;
e1fd234baac0 Tests: added HEAD method tests for js fetch API.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1783
diff changeset
606
1780
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
607 } elsif ($uri eq '/parted') {
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
608 print $client
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
609 "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
610 "Content-Length: 32000" . CRLF .
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
611 "Connection: close" . CRLF .
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
612 CRLF;
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
613
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
614 for (1 .. 4) {
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
615 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
616 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
617 }
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 } 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
620 print $client
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
621 "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
622 "Connection: close" . CRLF .
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
623 CRLF .
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
624 "CONTENT-BODY";
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
625
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
626 } 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
627 print $client
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
628 "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
629 "Connection: close" . CRLF .
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
630 CRLF;
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
631
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
632 for (1 .. 4) {
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
633 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
634 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
635 }
bd21a4a7c9f5 Tests: added js fetch tests for responses without Content-Length.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1758
diff changeset
636
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
637 } elsif ($uri eq '/big') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
638 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
639 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
640 "Content-Length: 100100" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
641 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
642 CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
643 for (1 .. 1000) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
644 print $client ("X" x 98) . 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 print $client "unfinished" . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
647
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
648 } elsif ($uri eq '/big/ok') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
649 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
650 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
651 "Content-Length: 100010" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
652 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
653 CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
654 for (1 .. 1000) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
655 print $client ("X" x 98) . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
656 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
657 print $client "finished" . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
658
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
659 } elsif ($uri eq '/chunked') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
660 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
661 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
662 "Transfer-Encoding: chunked" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
663 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
664 CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
665 "ff" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
666 "unfinished" . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
667
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
668 } elsif ($uri eq '/chunked/ok') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
669 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
670 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
671 "Transfer-Encoding: chunked" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
672 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
673 CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
674 "a" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
675 "finished" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
676 CRLF . "0" . CRLF . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
677 } elsif ($uri eq '/chunked/big') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
678 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
679 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
680 "Transfer-Encoding: chunked" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
681 "Bar: xxx" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
682 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
683 CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
684
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
685 for (1 .. 100) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
686 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
687 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
688
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
689 print $client "0" . CRLF . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
690 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
691 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
692 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
693
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
694 ###############################################################################