annotate js_fetch.t @ 1758:7c727869aeda

Tests: skip unsafe large header test in js_fetch.t.
author Dmitry Volyntsev <xeioex@nginx.com>
date Wed, 11 May 2022 09:23:40 -0700
parents 6966f099068d
children bd21a4a7c9f5
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
65 location /chain {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
66 js_content test.chain;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
67 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
68
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
69 location /chunked {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
70 js_content test.chunked;
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 /header {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
74 js_content test.header;
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
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
77 location /header_iter {
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
78 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
79 }
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
80
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
81 location /multi {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
82 js_content test.multi;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
83 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
84
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
85 location /property {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
86 js_content test.property;
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
90 server {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
91 listen 127.0.0.1:8080;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
92 server_name aaa;
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 location /loc {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
95 js_content test.loc;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
96 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
97
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
98 location /json { }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
99 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
100
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
101 server {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
102 listen 127.0.0.1:8080;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
103 server_name bbb;
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 location /loc {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
106 js_content test.loc;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
107 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
108 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
109
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
110 server {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
111 listen 127.0.0.1:8081;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
112 server_name ccc;
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 location /loc {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
115 js_content test.loc;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
116 }
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 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
119
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
120 EOF
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 my $p0 = port(8080);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
123 my $p1 = port(8081);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
124 my $p2 = port(8082);
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 $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
127
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
128 $t->write_file('test.js', <<EOF);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
129 function test_njs(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
130 r.return(200, njs.version);
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
133 function body(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
134 var loc = r.args.loc;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
135 var getter = r.args.getter;
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 query(obj) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
138 var path = r.args.path;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
139 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
140 : obj;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
141
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
142 if (path) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
143 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
144 }
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 return JSON.stringify(retval);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
147 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
148
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
149 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
150 .then(reply => reply[getter]())
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
151 .then(data => r.return(200, query(data)))
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
152 .catch(e => r.return(501, e.message))
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
153 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
154
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
155 function property(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
156 var opts = {headers:{Host: 'aaa'}};
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
157
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
158 if (r.args.code) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
159 opts.headers.code = r.args.code;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
160 }
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 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
163
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
164 if (r.args.readBody) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
165 p = p.then(rep =>
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
166 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
167 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
168
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
169 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
170 .catch(e => r.return(501, e.message))
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 function process_errors(r, tests) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
174 var results = [];
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 tests.forEach(args => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
177 ngx.fetch.apply(r, args)
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
178 .then(reply => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
179 r.return(400, '["unexpected then"]');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
180 })
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
181 .catch(e => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
182 results.push(e.message);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
183
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
184 if (results.length == tests.length) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
185 results.sort();
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
186 r.return(200, JSON.stringify(results));
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 })
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
189 })
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
190 }
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 function broken(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
193 var tests = [
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
194 ['http://127.0.0.1:1/loc'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
195 ['http://127.0.0.1:80800/loc'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
196 [Symbol.toStringTag],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
197 ];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
198
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
199 return process_errors(r, tests);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
200 }
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 function broken_response(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
203 var tests = [
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
204 ['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
205 ['http://127.0.0.1:$p2/length'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
206 ['http://127.0.0.1:$p2/header'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
207 ['http://127.0.0.1:$p2/headers'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
208 ['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
209 ];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
210
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
211 return process_errors(r, tests);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
212 }
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 function chain(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
215 var results = [];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
216 var reqs = [
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
217 ['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
218 ['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
219 ];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
220
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
221 function next(reply) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
222 if (reqs.length == 0) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
223 r.return(200, "SUCCESS");
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
224 return;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
225 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
226
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
227 ngx.fetch.apply(r, reqs.pop())
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
228 .then(next)
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
229 .catch(e => r.return(400, e.message))
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
232 next();
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
233 }
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 function chunked(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
236 var results = [];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
237 var tests = [
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
238 ['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
239 ['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
240 ['http://127.0.0.1:$p2/chunked'],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
241 ['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
242 ['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
243 ['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
244 ];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
245
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
246 function collect(v) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
247 results.push(v);
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 if (results.length == tests.length) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
250 results.sort();
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
251 r.return(200, JSON.stringify(results));
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 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
254
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
255 tests.forEach(args => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
256 ngx.fetch.apply(r, args)
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
257 .then(reply => reply.text())
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
258 .then(body => collect(body.length))
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
259 .catch(e => collect(e.message))
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
260 })
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
261 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
262
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
263 function header(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
264 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
265 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
266
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
267 var p = ngx.fetch(url)
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
268
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
269 if (r.args.readBody) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
270 p = p.then(rep =>
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
271 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
272 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
273
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
274 p.then(reply => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
275 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
276 r.return(200, njs.dump(h));
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 .catch(e => r.return(501, e.message))
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
279 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
280
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
281 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
282 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
283
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
284 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
285
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
286 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
287 let out = [];
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
288 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
289 if (key != 'Connection') {
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
290 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
291 }
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
292 }
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
293
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
294 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
295 }
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
296
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
297 function multi(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
298 var results = [];
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
299 var tests = [
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
300 [
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
301 'http://127.0.0.1:$p0/loc',
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
302 { headers: {Code: 201, Host: 'aaa'}},
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
303 ],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
304 [
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
305 'http://127.0.0.1:$p0/loc',
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
306 { 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
307 ],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
308 [
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
309 'http://127.0.0.1:$p1/loc',
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
310 { method:'PATCH',
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
311 headers: {foo:undefined, bar:'xxx', Host: 'ccc'}},
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
312 ],
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
313 ];
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 function cmp(a,b) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
316 if (a.b > b.b) {return 1;}
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
317 if (a.b < b.b) {return -1;}
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
318 return 0
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
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
321 tests.forEach(args => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
322 ngx.fetch.apply(r, args)
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
323 .then(rep =>
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
324 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
325 .then(rep => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
326 results.push({b:rep.text,
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
327 c:rep.status,
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
328 u:rep.url});
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
329
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
330 if (results.length == tests.length) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
331 results.sort(cmp);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
332 r.return(200, JSON.stringify(results));
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
333 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
334 })
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
335 .catch(e => {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
336 r.return(400, `["\${e.message}"]`);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
337 throw e;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
338 })
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
339 })
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
340
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
341 if (r.args.throw) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
342 throw 'Oops';
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
343 }
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 function str(v) { return v ? v : ''};
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
347
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
348 function loc(r) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
349 var v = r.variables;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
350 var body = str(r.requestText);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
351 var foo = str(r.headersIn.foo);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
352 var bar = str(r.headersIn.bar);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
353 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
354 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
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 export default {njs: test_njs, body, broken, broken_response,
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
358 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
359 EOF
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
360
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
361 $t->try_run('no njs.fetch')->plan(28);
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
362
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
363 $t->run_daemon(\&http_daemon, port(8082));
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
364 $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
365
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
366 ###############################################################################
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
367
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
368 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
369 'fetch body arrayBuffer');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
370 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
371 'fetch body text');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
372 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
373 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
374 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
375 'fetch body json invalid');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
376 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
377 'fetch bodyUsed false');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
378 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
379 'fetch bodyUsed true');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
380 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
381 'fetch ok true');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
382 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
383 'fetch ok false');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
384 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
385 'fetch redirected false');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
386 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
387 'fetch statusText OK');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
388 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
389 'fetch statusText Forbidden');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
390 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
391 'fetch type');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
392 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
393 'fetch header');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
394 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
395 'fetch no header');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
396 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
397 'fetch header duplicate');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
398 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
399 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
400 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
401 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
402 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
403 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
404 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
405 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
406 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
407 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
408 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
409 'fetch chunked header');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
410 is(get_json('/multi'),
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
411 '[{"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
412 '{"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
413 '{"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
414 'fetch multi');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
415 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
416 is(get_json('/broken'),
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
417 '[' .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
418 '"connect failed",' .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
419 '"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
420 '"invalid url"]', 'fetch broken');
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
421 is(get_json('/broken_response'),
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
422 '["invalid fetch content length",' .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
423 '"invalid fetch header",' .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
424 '"invalid fetch status line",' .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
425 '"prematurely closed connection",' .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
426 '"prematurely closed connection"]', 'fetch broken response');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
427 is(get_json('/chunked'),
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
428 '[10,100010,25500,' .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
429 '"invalid fetch chunked response",' .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
430 '"prematurely closed connection",' .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
431 '"very large fetch chunked response"]', 'fetch chunked');
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
432 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
433
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
434 TODO: {
1758
7c727869aeda Tests: skip unsafe large header test in js_fetch.t.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1756
diff changeset
435 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
436 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
437
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
438 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
439 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
440 '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
441
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
442 }
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
443
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
444 ###############################################################################
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
445
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
446 sub recode {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
447 my $json;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
448 eval { $json = JSON::PP::decode_json(shift) };
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
449
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
450 if ($@) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
451 return "<failed to parse JSON>";
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
452 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
453
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
454 JSON::PP->new()->canonical()->encode($json);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
455 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
456
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
457 sub get_json {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
458 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
459 recode($1);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
460 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
461
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
462 ###############################################################################
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
463
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
464 sub http_daemon {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
465 my $port = shift;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
466
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
467 my $server = IO::Socket::INET->new(
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
468 Proto => 'tcp',
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
469 LocalAddr => '127.0.0.1:' . $port,
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
470 Listen => 5,
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
471 Reuse => 1
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
472 ) 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
473
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
474 local $SIG{PIPE} = 'IGNORE';
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
475
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
476 while (my $client = $server->accept()) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
477 $client->autoflush(1);
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
478
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
479 my $headers = '';
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
480 my $uri = '';
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
481
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
482 while (<$client>) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
483 $headers .= $_;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
484 last if (/^\x0d?\x0a?$/);
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 $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
488
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
489 if ($uri eq '/status_line') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
490 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
491 "HTTP/1.1 2A";
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
492
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
493 } elsif ($uri eq '/content_length') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
494 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
495 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
496 "Content-Length: " . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
497 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
498 CRLF;
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 } elsif ($uri eq '/header') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
501 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
502 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
503 "@#" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
504 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
505 CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
506
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
507 } elsif ($uri eq '/duplicate_header') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
508 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
509 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
510 "Foo: a" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
511 "bar: c" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
512 "Foo: b" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
513 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
514 CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
515
1756
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
516 } 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
517 print $client
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
518 "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
519 "A: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
520 "B: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
521 "C: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
522 "D: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
523 "E: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
524 "F: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
525 "G: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
526 "H: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
527 "Foo: a" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
528 "Foo: b" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
529 "Connection: close" . CRLF .
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
530 CRLF;
6966f099068d Tests: added js fetch tests for a response with many headers.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1727
diff changeset
531
1640
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
532 } elsif ($uri eq '/headers') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
533 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
534 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
535 "Connection: close" . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
536
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
537 } elsif ($uri eq '/length') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
538 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
539 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
540 "Content-Length: 100" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
541 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
542 CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
543 "unfinished" . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
544
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
545 } elsif ($uri eq '/big') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
546 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
547 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
548 "Content-Length: 100100" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
549 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
550 CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
551 for (1 .. 1000) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
552 print $client ("X" x 98) . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
553 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
554 print $client "unfinished" . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
555
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
556 } elsif ($uri eq '/big/ok') {
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 "Content-Length: 100010" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
560 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
561 CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
562 for (1 .. 1000) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
563 print $client ("X" x 98) . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
564 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
565 print $client "finished" . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
566
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
567 } elsif ($uri eq '/chunked') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
568 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
569 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
570 "Transfer-Encoding: chunked" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
571 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
572 CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
573 "ff" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
574 "unfinished" . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
575
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
576 } elsif ($uri eq '/chunked/ok') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
577 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
578 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
579 "Transfer-Encoding: chunked" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
580 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
581 CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
582 "a" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
583 "finished" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
584 CRLF . "0" . CRLF . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
585 } elsif ($uri eq '/chunked/big') {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
586 print $client
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
587 "HTTP/1.1 200 OK" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
588 "Transfer-Encoding: chunked" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
589 "Bar: xxx" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
590 "Connection: close" . CRLF .
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
591 CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
592
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
593 for (1 .. 100) {
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
594 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
595 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
596
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
597 print $client "0" . CRLF . CRLF;
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
598 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
599 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
600 }
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
601
67adc5fd0548 Tests: added js tests for ngx.fetch() method.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
602 ###############################################################################