Mercurial > hg > nginx-tests
comparison js_headers.t @ 1563:c1d167a13c24
Tests: added js tests for multi-values headers.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Tue, 21 Apr 2020 12:12:31 +0000 |
parents | ca0858ef7d3d |
children | 84a1e16819e5 |
comparison
equal
deleted
inserted
replaced
1562:b4f528987146 | 1563:c1d167a13c24 |
---|---|
52 | 52 |
53 location /content_length { | 53 location /content_length { |
54 js_content content_length; | 54 js_content content_length; |
55 } | 55 } |
56 | 56 |
57 location /content_length_arr { | |
58 js_content content_length_arr; | |
59 } | |
60 | |
61 location /content_length_keys { | |
62 js_content content_length_keys; | |
63 } | |
64 | |
57 location /content_type { | 65 location /content_type { |
58 charset windows-1251; | 66 charset windows-1251; |
59 | 67 |
60 default_type text/plain; | 68 default_type text/plain; |
61 js_content content_type; | 69 js_content content_type; |
62 } | 70 } |
63 | 71 |
72 location /content_type_arr { | |
73 charset windows-1251; | |
74 | |
75 default_type text/plain; | |
76 js_content content_type_arr; | |
77 } | |
78 | |
64 location /content_encoding { | 79 location /content_encoding { |
65 js_content content_encoding; | 80 js_content content_encoding; |
66 } | 81 } |
67 | 82 |
83 location /content_encoding_arr { | |
84 js_content content_encoding_arr; | |
85 } | |
86 | |
68 location /headers_list { | 87 location /headers_list { |
69 js_content headers_list; | 88 js_content headers_list; |
70 } | 89 } |
71 | 90 |
72 location /foo_in { | 91 location /foo_in { |
81 js_content hdr_in; | 100 js_content hdr_in; |
82 } | 101 } |
83 | 102 |
84 location /hdr_out { | 103 location /hdr_out { |
85 js_content hdr_out; | 104 js_content hdr_out; |
105 } | |
106 | |
107 location /hdr_out_array { | |
108 js_content hdr_out_array; | |
109 } | |
110 | |
111 location /hdr_out_set_cookie { | |
112 js_content hdr_out_set_cookie; | |
113 } | |
114 | |
115 location /hdr_out_single { | |
116 js_content hdr_out_single; | |
86 } | 117 } |
87 | 118 |
88 location /ihdr_out { | 119 location /ihdr_out { |
89 js_content ihdr_out; | 120 js_content ihdr_out; |
90 } | 121 } |
110 r.sendHeader(); | 141 r.sendHeader(); |
111 r.send('XXX'); | 142 r.send('XXX'); |
112 r.finish(); | 143 r.finish(); |
113 } | 144 } |
114 | 145 |
146 function content_length_arr(r) { | |
147 r.headersOut['Content-Length'] = [5]; | |
148 r.headersOut['Content-Length'] = []; | |
149 r.headersOut['Content-Length'] = [4,3]; | |
150 r.sendHeader(); | |
151 r.send('XXX'); | |
152 r.finish(); | |
153 } | |
154 | |
155 function content_length_keys(r) { | |
156 r.headersOut['Content-Length'] = 3; | |
157 var in_keys = Object.keys(r.headersOut).some(v=>v=='Content-Length'); | |
158 r.return(200, `B:\${in_keys}`); | |
159 } | |
160 | |
115 function content_type(r) { | 161 function content_type(r) { |
116 r.headersOut['Content-Type'] = 'text/xml'; | 162 r.headersOut['Content-Type'] = 'text/xml'; |
117 r.headersOut['Content-Type'] = ''; | 163 r.headersOut['Content-Type'] = ''; |
118 r.headersOut['Content-Type'] = 'text/xml; charset='; | 164 r.headersOut['Content-Type'] = 'text/xml; charset='; |
119 delete r.headersOut['Content-Type']; | 165 delete r.headersOut['Content-Type']; |
120 r.headersOut['Content-Type'] = 'text/xml; charset=utf-8'; | 166 r.headersOut['Content-Type'] = 'text/xml; charset=utf-8'; |
121 r.headersOut['Content-Type'] = 'text/xml; charset="utf-8"'; | 167 r.headersOut['Content-Type'] = 'text/xml; charset="utf-8"'; |
168 var in_keys = Object.keys(r.headersOut).some(v=>v=='Content-Type'); | |
169 r.return(200, `B:\${in_keys}`); | |
170 } | |
171 | |
172 function content_type_arr(r) { | |
173 r.headersOut['Content-Type'] = ['text/html']; | |
174 r.headersOut['Content-Type'] = []; | |
175 r.headersOut['Content-Type'] = [ 'text/xml', 'text/html']; | |
122 r.return(200); | 176 r.return(200); |
123 } | 177 } |
124 | 178 |
125 function content_encoding(r) { | 179 function content_encoding(r) { |
126 r.headersOut['Content-Encoding'] = ''; | 180 r.headersOut['Content-Encoding'] = ''; |
128 delete r.headersOut['Content-Encoding']; | 182 delete r.headersOut['Content-Encoding']; |
129 r.headersOut['Content-Encoding'] = 'gzip'; | 183 r.headersOut['Content-Encoding'] = 'gzip'; |
130 r.return(200); | 184 r.return(200); |
131 } | 185 } |
132 | 186 |
187 function content_encoding_arr(r) { | |
188 r.headersOut['Content-Encoding'] = 'test'; | |
189 r.headersOut['Content-Encoding'] = []; | |
190 r.headersOut['Content-Encoding'] = ['test', 'gzip']; | |
191 r.return(200); | |
192 } | |
193 | |
133 function headers_list(r) { | 194 function headers_list(r) { |
134 for (var h in {a:1, b:2, c:3}) { | 195 for (var h in {a:1, b:2, c:3}) { |
135 r.headersOut[h] = h; | 196 r.headersOut[h] = h; |
136 } | 197 } |
137 | 198 |
193 | 254 |
194 r.sendHeader(); | 255 r.sendHeader(); |
195 r.finish(); | 256 r.finish(); |
196 } | 257 } |
197 | 258 |
259 function hdr_out_array(r) { | |
260 if (!r.args.hidden) { | |
261 r.headersOut['Foo'] = [r.args.fOO]; | |
262 r.headersOut['Foo'] = []; | |
263 r.headersOut['Foo'] = ['bar', r.args.fOO]; | |
264 } | |
265 | |
266 if (r.args.scalar_set) { | |
267 r.headersOut['Foo'] = 'xxx'; | |
268 } | |
269 | |
270 r.return(200, `B:\${njs.dump(r.headersOut.foo)}`); | |
271 } | |
272 | |
273 function hdr_out_single(r) { | |
274 r.headersOut.ETag = ['a', 'b']; | |
275 r.return(200, `B:\${njs.dump(r.headersOut.etag)}`); | |
276 } | |
277 | |
278 function hdr_out_set_cookie(r) { | |
279 r.headersOut['Set-Cookie'] = []; | |
280 r.headersOut['Set-Cookie'] = ['a', 'b']; | |
281 delete r.headersOut['Set-Cookie']; | |
282 r.headersOut['Set-Cookie'] = 'e'; | |
283 r.headersOut['Set-Cookie'] = ['c', '', null, 'd', 'f']; | |
284 | |
285 r.return(200, `B:\${njs.dump(r.headersOut['Set-Cookie'])}`); | |
286 } | |
287 | |
198 function ihdr_out(r) { | 288 function ihdr_out(r) { |
199 r.status = 200; | 289 r.status = 200; |
200 r.headersOut['a'] = r.args.a; | 290 r.headersOut['a'] = r.args.a; |
201 r.headersOut['b'] = r.args.b; | 291 r.headersOut['b'] = r.args.b; |
202 | 292 |
211 } | 301 } |
212 | 302 |
213 | 303 |
214 EOF | 304 EOF |
215 | 305 |
216 $t->try_run('no njs')->plan(18); | 306 $t->try_run('no njs')->plan(34); |
217 | 307 |
218 ############################################################################### | 308 ############################################################################### |
219 | 309 |
220 like(http_get('/content_length'), qr/Content-Length: 3/, | 310 like(http_get('/content_length'), qr/Content-Length: 3/, |
221 'set Content-Length'); | 311 'set Content-Length'); |
233 like(http_get('/hdr_out?foo=123&bar=copy'), qr/Bar: 123/, 'r.headersOut get'); | 323 like(http_get('/hdr_out?foo=123&bar=copy'), qr/Bar: 123/, 'r.headersOut get'); |
234 unlike(http_get('/hdr_out?bar=empty'), qr/Bar:/, 'r.headersOut empty'); | 324 unlike(http_get('/hdr_out?bar=empty'), qr/Bar:/, 'r.headersOut empty'); |
235 unlike(http_get('/hdr_out?foo='), qr/Foo:/, 'r.headersOut no value'); | 325 unlike(http_get('/hdr_out?foo='), qr/Foo:/, 'r.headersOut no value'); |
236 unlike(http_get('/hdr_out?foo'), qr/Foo:/, 'r.headersOut no value 2'); | 326 unlike(http_get('/hdr_out?foo'), qr/Foo:/, 'r.headersOut no value 2'); |
237 | 327 |
328 TODO: { | |
329 local $TODO = 'not yet' | |
330 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.4.0'; | |
331 | |
332 like(http_get('/content_length_keys'), qr/B:true/, 'Content-Length in keys'); | |
333 like(http_get('/content_length_arr'), qr/Content-Length: 3/, | |
334 'set Content-Length arr'); | |
335 | |
336 like(http_get('/content_type'), qr/B:true/, 'Content-Type in keys'); | |
337 like(http_get('/content_type_arr'), qr/Content-Type: text\/html/, | |
338 'set Content-Type arr'); | |
339 like(http_get('/content_encoding_arr'), qr/Content-Encoding: gzip/, | |
340 'set Content-Encoding arr'); | |
341 | |
342 like(http_get('/hdr_out_array?foo=12345'), qr/Foo: bar\r\nFoo: 12345/, | |
343 'r.headersOut arr'); | |
344 like(http_get('/hdr_out_array'), qr/Foo: bar/, | |
345 'r.headersOut arr last is empty'); | |
346 like(http_get('/hdr_out_array?foo=abc'), qr/B:bar,abc/, | |
347 'r.headersOut get'); | |
348 like(http_get('/hdr_out_array'), qr/B:bar/, 'r.headersOut get2'); | |
349 like(http_get('/hdr_out_array?hidden=1'), qr/B:undefined/, | |
350 'r.headersOut get3'); | |
351 like(http_get('/hdr_out_array?scalar_set=1'), qr/B:xxx/, | |
352 'r.headersOut scalar set'); | |
353 like(http_get('/hdr_out_single'), qr/ETag: a\r\nETag: b/, | |
354 'r.headersOut single'); | |
355 like(http_get('/hdr_out_single'), qr/B:a/, | |
356 'r.headersOut single get'); | |
357 like(http_get('/hdr_out_set_cookie'), qr/Set-Cookie: c\r\nSet-Cookie: d/, | |
358 'set_cookie'); | |
359 like(http_get('/hdr_out_set_cookie'), qr/B:\['c','d','f']/, | |
360 'set_cookie2'); | |
361 unlike(http_get('/hdr_out_set_cookie'), qr/Set-Cookie: [abe]/, | |
362 'set_cookie3'); | |
363 | |
364 } | |
365 | |
238 like(http( | 366 like(http( |
239 'GET /hdr_in HTTP/1.0' . CRLF | 367 'GET /hdr_in HTTP/1.0' . CRLF |
240 . 'Cookie: foo' . CRLF | 368 . 'Cookie: foo' . CRLF |
241 . 'Host: localhost' . CRLF . CRLF | 369 . 'Host: localhost' . CRLF . CRLF |
242 ), qr/cookie: foo/, 'r.headersIn cookie'); | 370 ), qr/cookie: foo/, 'r.headersIn cookie'); |
248 ), qr/x-forwarded-for: foo/, 'r.headersIn xff'); | 376 ), qr/x-forwarded-for: foo/, 'r.headersIn xff'); |
249 | 377 |
250 | 378 |
251 TODO: { | 379 TODO: { |
252 local $TODO = 'not yet' | 380 local $TODO = 'not yet' |
253 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.6'; | 381 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.6'; |
254 | 382 |
255 like(http( | 383 like(http( |
256 'GET /hdr_in HTTP/1.0' . CRLF | 384 'GET /hdr_in HTTP/1.0' . CRLF |
257 . 'Cookie: foo1' . CRLF | 385 . 'Cookie: foo1' . CRLF |
258 . 'Cookie: foo2' . CRLF | 386 . 'Cookie: foo2' . CRLF |
268 | 396 |
269 } | 397 } |
270 | 398 |
271 TODO: { | 399 TODO: { |
272 local $TODO = 'not yet' | 400 local $TODO = 'not yet' |
273 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.7'; | 401 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.7'; |
274 | 402 |
275 like(http( | 403 like(http( |
276 'GET /hdr_sorted_keys?in=1 HTTP/1.0' . CRLF | 404 'GET /hdr_sorted_keys?in=1 HTTP/1.0' . CRLF |
277 . 'Cookie: foo1' . CRLF | 405 . 'Cookie: foo1' . CRLF |
278 . 'Accept: */*' . CRLF | 406 . 'Accept: */*' . CRLF |