comparison src/http/modules/perl/nginx.xs @ 5248:f5626ab8cb87

Perl: fixed r->header_in("Cookie") (ticket #351). It was broken by X-Forwarded-For related changes in f7fe817c92a2 (1.3.14) as hh->offset is no longer 0 for Cookie.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 10 Jun 2013 14:35:00 +0400
parents e530b88b088b
children 43900b822890
comparison
equal deleted inserted replaced
5247:55dc535ae5dc 5248:f5626ab8cb87
220 CODE: 220 CODE:
221 221
222 dXSTARG; 222 dXSTARG;
223 ngx_http_request_t *r; 223 ngx_http_request_t *r;
224 SV *key; 224 SV *key;
225 u_char *p, *lowcase_key, *cookie; 225 u_char *p, *lowcase_key, *value, sep;
226 STRLEN len; 226 STRLEN len;
227 ssize_t size; 227 ssize_t size;
228 ngx_uint_t i, n, hash; 228 ngx_uint_t i, n, hash;
229 ngx_array_t *a;
229 ngx_list_part_t *part; 230 ngx_list_part_t *part;
230 ngx_table_elt_t *h, **ph; 231 ngx_table_elt_t *h, **ph;
231 ngx_http_header_t *hh; 232 ngx_http_header_t *hh;
232 ngx_http_core_main_conf_t *cmcf; 233 ngx_http_core_main_conf_t *cmcf;
233 234
253 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); 254 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
254 255
255 hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len); 256 hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len);
256 257
257 if (hh) { 258 if (hh) {
259
260 if (hh->offset == offsetof(ngx_http_headers_in_t, cookies)) {
261 sep = ';';
262 goto multi;
263 }
264
265 #if (NGX_HTTP_X_FORWARDED_FOR)
266 if (hh->offset == offsetof(ngx_http_headers_in_t, x_forwarded_for)) {
267 sep = ',';
268 goto multi;
269 }
270 #endif
271
258 if (hh->offset) { 272 if (hh->offset) {
259 273
260 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset); 274 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset);
261 275
262 if (*ph) { 276 if (*ph) {
266 } 280 }
267 281
268 XSRETURN_UNDEF; 282 XSRETURN_UNDEF;
269 } 283 }
270 284
271 /* Cookie */ 285 multi:
272 286
273 n = r->headers_in.cookies.nelts; 287 /* Cookie, X-Forwarded-For */
288
289 a = (ngx_array_t *) ((char *) &r->headers_in + hh->offset);
290
291 n = a->nelts;
274 292
275 if (n == 0) { 293 if (n == 0) {
276 XSRETURN_UNDEF; 294 XSRETURN_UNDEF;
277 } 295 }
278 296
279 ph = r->headers_in.cookies.elts; 297 ph = a->elts;
280 298
281 if (n == 1) { 299 if (n == 1) {
282 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); 300 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
283 301
284 goto done; 302 goto done;
288 306
289 for (i = 0; i < n; i++) { 307 for (i = 0; i < n; i++) {
290 size += ph[i]->value.len + sizeof("; ") - 1; 308 size += ph[i]->value.len + sizeof("; ") - 1;
291 } 309 }
292 310
293 cookie = ngx_pnalloc(r->pool, size); 311 value = ngx_pnalloc(r->pool, size);
294 if (cookie == NULL) { 312 if (value == NULL) {
295 XSRETURN_UNDEF; 313 XSRETURN_UNDEF;
296 } 314 }
297 315
298 p = cookie; 316 p = value;
299 317
300 for (i = 0; /* void */ ; i++) { 318 for (i = 0; /* void */ ; i++) {
301 p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len); 319 p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len);
302 320
303 if (i == n - 1) { 321 if (i == n - 1) {
304 break; 322 break;
305 } 323 }
306 324
307 *p++ = ';'; *p++ = ' '; 325 *p++ = sep; *p++ = ' ';
308 } 326 }
309 327
310 ngx_http_perl_set_targ(cookie, size); 328 ngx_http_perl_set_targ(value, size);
311 329
312 goto done; 330 goto done;
313 } 331 }
314 332
315 /* iterate over all headers */ 333 /* iterate over all headers */