comparison js.t @ 993:3ee5ca1ec728

Tests: updated js.t to the new http js module syntax.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 25 Jul 2016 16:20:37 +0300
parents 882267679006
children 345a655ef643
comparison
equal deleted inserted replaced
992:1beb641e21c9 993:3ee5ca1ec728
32 } 32 }
33 33
34 http { 34 http {
35 %%TEST_GLOBALS_HTTP%% 35 %%TEST_GLOBALS_HTTP%%
36 36
37 js_set $test_method "'method=' + $r.method"; 37 js_set $test_method test_method;
38 js_set $test_version "'version=' + $r.httpVersion"; 38 js_set $test_version test_version;
39 js_set $test_addr "'addr=' + $r.remoteAddress"; 39 js_set $test_addr test_addr;
40 js_set $test_uri "'uri=' + $r.uri"; 40 js_set $test_uri test_uri;
41 js_set $test_hdr "'hdr=' + $r.headers.foo"; 41 js_set $test_hdr test_hdr;
42 js_set $test_ihdr "var s; 42 js_set $test_ihdr test_ihdr;
43 s = ''; 43 js_set $test_arg test_arg;
44 for (h in $r.headers) { 44 js_set $test_iarg test_iarg;
45 if (h.substr(0, 3) == 'foo') { 45
46 s += $r.headers[h]; 46 js_include test.js;
47 }
48 }
49 s;";
50 js_set $test_arg "'arg=' + $r.args.foo";
51 js_set $test_iarg "var s;
52 s = '';
53 for (a in $r.args) {
54 if (a.substr(0, 3) == 'foo') {
55 s += $r.args[a];
56 }
57 }
58 s;";
59 47
60 server { 48 server {
61 listen 127.0.0.1:8080; 49 listen 127.0.0.1:8080;
62 server_name localhost; 50 server_name localhost;
63 51
92 location /req_iarg { 80 location /req_iarg {
93 return 200 $test_iarg; 81 return 200 $test_iarg;
94 } 82 }
95 83
96 location /res_status { 84 location /res_status {
97 js_run " 85 js_content status;
98 var res;
99 res = $r.response;
100 res.status = 204;
101 res.sendHeader();
102 res.finish();
103 ";
104 } 86 }
105 87
106 location /res_ctype { 88 location /res_ctype {
107 js_run " 89 js_content ctype;
108 var res;
109 res = $r.response;
110 res.status = 200;
111 res.contentType = 'application/foo';
112 res.sendHeader();
113 res.finish();
114 ";
115 } 90 }
116 91
117 location /res_clen { 92 location /res_clen {
118 js_run " 93 js_content clen;
119 var res;
120 res = $r.response;
121 res.status = 200;
122 res.contentLength = 5;
123 res.sendHeader();
124 res.send('foo12');
125 res.finish();
126 ";
127 } 94 }
128 95
129 location /res_send { 96 location /res_send {
130 js_run " 97 js_content send;
131 var res, a, s;
132 res = $r.response;
133 res.status = 200;
134 res.sendHeader();
135 for (a in $r.args) {
136 if (a.substr(0, 3) == 'foo') {
137 s = $r.args[a];
138 res.send('n=' + a + ', v=' + s.substr(0, 2) + ' ');
139 }
140 }
141 res.finish();
142 ";
143 } 98 }
144 99
145 location /res_hdr { 100 location /res_hdr {
146 js_run " 101 js_content hdr;
147 var res; 102 }
148 res = $r.response; 103 }
149 res.status = 200; 104 }
150 res.headers['Foo'] = $r.args.fOO; 105
151 res.sendHeader(); 106 EOF
152 res.finish(); 107
153 "; 108 $t->write_file('test.js', <<EOF);
154 } 109 function test_method(req, res) {
155 } 110 return 'method=' + req.method;
156 } 111 }
157 112
113 function test_version(req, res) {
114 return 'version=' + req.httpVersion;
115 }
116
117 function test_addr(req, res) {
118 return 'addr=' + req.remoteAddress;
119 }
120
121 function test_uri(req, res) {
122 return 'uri=' + req.uri;
123 }
124
125 function test_hdr(req, res) {
126 return 'hdr=' + req.headers.foo;
127 }
128
129 function test_ihdr(req, res) {
130 var s;
131 s = '';
132 for (h in req.headers) {
133 if (h.substr(0, 3) == 'foo') {
134 s += req.headers[h];
135 }
136 }
137 return s;
138 }
139
140 function test_arg(req, res) {
141 return 'arg=' + req.args.foo;
142 }
143
144 function test_iarg(req, res) {
145 var s;
146 s = '';
147 for (a in req.args) {
148 if (a.substr(0, 3) == 'foo') {
149 s += req.args[a];
150 }
151 }
152 return s;
153 }
154
155 function status(req, res) {
156 res.status = 204;
157 res.sendHeader();
158 res.finish();
159 }
160
161 function ctype(req, res) {
162 res.status = 200;
163 res.contentType = 'application/foo';
164 res.sendHeader();
165 res.finish();
166 }
167
168 function clen(req, res) {
169 res.status = 200;
170 res.contentLength = 5;
171 res.sendHeader();
172 res.send('foo12');
173 res.finish();
174 }
175
176 function send(req, res) {
177 var a, s;
178 res.status = 200;
179 res.sendHeader();
180 for (a in req.args) {
181 if (a.substr(0, 3) == 'foo') {
182 s = req.args[a];
183 res.send('n=' + a + ', v=' + s.substr(0, 2) + ' ');
184 }
185 }
186 res.finish();
187 }
188
189 function hdr(req, res) {
190 res.status = 200;
191 res.headers['Foo'] = req.args.fOO;
192 res.sendHeader();
193 res.finish();
194 }
158 EOF 195 EOF
159 196
160 $t->try_run('no njs available')->plan(13); 197 $t->try_run('no njs available')->plan(13);
161 198
162 ############################################################################### 199 ###############################################################################