annotate js_fetch.t @ 1783:95ba1e704b7b

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