Mercurial > hg > nginx-tests
comparison js_headers.t @ 1440:5d0eb718f38e
Tests: moved njs http headers test to a separate file.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Thu, 07 Feb 2019 20:24:02 +0300 |
parents | c083749bc47d |
children | 1220f0055135 |
comparison
equal
deleted
inserted
replaced
1439:c083749bc47d | 1440:5d0eb718f38e |
---|---|
34 events { | 34 events { |
35 } | 35 } |
36 | 36 |
37 http { | 37 http { |
38 %%TEST_GLOBALS_HTTP%% | 38 %%TEST_GLOBALS_HTTP%% |
39 | |
40 js_set $test_hdr_in test_hdr_in; | |
41 js_set $test_ihdr_in test_ihdr_in; | |
39 | 42 |
40 js_include test.js; | 43 js_include test.js; |
41 | 44 |
42 server { | 45 server { |
43 listen 127.0.0.1:8080; | 46 listen 127.0.0.1:8080; |
62 js_content content_encoding; | 65 js_content content_encoding; |
63 } | 66 } |
64 | 67 |
65 location /headers_list { | 68 location /headers_list { |
66 js_content headers_list; | 69 js_content headers_list; |
70 } | |
71 | |
72 location /hdr_in { | |
73 return 200 $test_hdr_in; | |
74 } | |
75 | |
76 location /ihdr_in { | |
77 return 200 $test_ihdr_in; | |
78 } | |
79 | |
80 location /hdr_out { | |
81 js_content hdr_out; | |
82 } | |
83 | |
84 location /ihdr_out { | |
85 js_content ihdr_out; | |
67 } | 86 } |
68 } | 87 } |
69 } | 88 } |
70 | 89 |
71 EOF | 90 EOF |
117 } | 136 } |
118 | 137 |
119 r.return(200, out); | 138 r.return(200, out); |
120 } | 139 } |
121 | 140 |
141 function test_hdr_in(r) { | |
142 return 'hdr=' + r.headersIn.foo; | |
143 } | |
144 | |
145 function test_ihdr_in(r) { | |
146 var s = '', h; | |
147 for (h in r.headersIn) { | |
148 if (h.substr(0, 3) == 'foo') { | |
149 s += r.headersIn[h]; | |
150 } | |
151 } | |
152 return s; | |
153 } | |
154 | |
155 function hdr_out(r) { | |
156 r.status = 200; | |
157 r.headersOut['Foo'] = r.args.fOO; | |
158 | |
159 if (r.args.bar) { | |
160 r.headersOut['Bar'] = | |
161 r.headersOut[(r.args.bar == 'empty' ? 'Baz' :'Foo')] | |
162 } | |
163 | |
164 r.sendHeader(); | |
165 r.finish(); | |
166 } | |
167 | |
168 function ihdr_out(r) { | |
169 r.status = 200; | |
170 r.headersOut['a'] = r.args.a; | |
171 r.headersOut['b'] = r.args.b; | |
172 | |
173 var s = '', h; | |
174 for (h in r.headersOut) { | |
175 s += r.headersOut[h]; | |
176 } | |
177 | |
178 r.sendHeader(); | |
179 r.send(s); | |
180 r.finish(); | |
181 } | |
182 | |
183 | |
122 EOF | 184 EOF |
123 | 185 |
124 $t->try_run('no njs')->plan(5); | 186 $t->try_run('no njs')->plan(12); |
125 | 187 |
126 ############################################################################### | 188 ############################################################################### |
127 | 189 |
128 | 190 |
129 TODO: { | 191 TODO: { |
138 'set Content-Type 2'); | 200 'set Content-Type 2'); |
139 like(http_get('/content_encoding'), qr/Content-Encoding: gzip/, | 201 like(http_get('/content_encoding'), qr/Content-Encoding: gzip/, |
140 'set Content-Encoding'); | 202 'set Content-Encoding'); |
141 like(http_get('/headers_list'), qr/a:c:d/, 'headers list'); | 203 like(http_get('/headers_list'), qr/a:c:d/, 'headers list'); |
142 | 204 |
205 like(http_get('/ihdr_out?a=12&b=34'), qr/^1234$/m, 'r.headersOut iteration'); | |
206 like(http_get('/ihdr_out'), qr/\x0d\x0a?\x0d\x0a?$/m, 'r.send zero'); | |
207 like(http_get('/hdr_out?foo=12345'), qr/Foo: 12345/, 'r.headersOut'); | |
208 like(http_get('/hdr_out?foo=123&bar=copy'), qr/Bar: 123/, 'r.headersOut get'); | |
209 unlike(http_get('/hdr_out?bar=empty'), qr/Bar:/, 'r.headersOut empty'); | |
210 unlike(http_get('/hdr_out?foo='), qr/Foo:/, 'r.headersOut no value'); | |
211 unlike(http_get('/hdr_out?foo'), qr/Foo:/, 'r.headersOut no value 2'); | |
143 } | 212 } |
144 | 213 |
145 ############################################################################### | 214 ############################################################################### |