comparison src/http/modules/perl/nginx.xs @ 8027:ca78312db071

Perl: combining unknown headers during $r->header_in() lookup.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 May 2022 21:25:38 +0300
parents 8b3860b52bb3
children d26db4f82d7d
comparison
equal deleted inserted replaced
8026:8b3860b52bb3 8027:ca78312db071
270 STRLEN len; 270 STRLEN len;
271 ssize_t size; 271 ssize_t size;
272 ngx_uint_t i, n, hash; 272 ngx_uint_t i, n, hash;
273 ngx_array_t *a; 273 ngx_array_t *a;
274 ngx_list_part_t *part; 274 ngx_list_part_t *part;
275 ngx_table_elt_t *h, **ph; 275 ngx_table_elt_t *h, *header, **ph;
276 ngx_http_header_t *hh; 276 ngx_http_header_t *hh;
277 ngx_http_core_main_conf_t *cmcf; 277 ngx_http_core_main_conf_t *cmcf;
278 278
279 ngx_http_perl_set_request(r, ctx); 279 ngx_http_perl_set_request(r, ctx);
280 280
309 sep = ','; 309 sep = ',';
310 } 310 }
311 311
312 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset); 312 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset);
313 313
314 if (*ph == NULL) { 314 goto found;
315 XSRETURN_UNDEF;
316 }
317
318 if ((*ph)->next == NULL) {
319 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
320
321 goto done;
322 }
323
324 size = - (ssize_t) (sizeof("; ") - 1);
325
326 for (h = *ph; h; h = h->next) {
327 size += h->value.len + sizeof("; ") - 1;
328 }
329
330 value = ngx_pnalloc(r->pool, size);
331 if (value == NULL) {
332 ctx->error = 1;
333 croak("ngx_pnalloc() failed");
334 }
335
336 p = value;
337
338 for (h = *ph; h; h = h->next) {
339 p = ngx_copy(p, h->value.data, h->value.len);
340
341 if (h->next == NULL) {
342 break;
343 }
344
345 *p++ = sep; *p++ = ' ';
346 }
347
348 ngx_http_perl_set_targ(value, size);
349
350 goto done;
351 } 315 }
352 316
353 /* iterate over all headers */ 317 /* iterate over all headers */
318
319 sep = ',';
320 ph = &header;
354 321
355 part = &r->headers_in.headers.part; 322 part = &r->headers_in.headers.part;
356 h = part->elts; 323 h = part->elts;
357 324
358 for (i = 0; /* void */ ; i++) { 325 for (i = 0; /* void */ ; i++) {
371 || ngx_strcasecmp(p, h[i].key.data) != 0) 338 || ngx_strcasecmp(p, h[i].key.data) != 0)
372 { 339 {
373 continue; 340 continue;
374 } 341 }
375 342
376 ngx_http_perl_set_targ(h[i].value.data, h[i].value.len); 343 *ph = &h[i];
377 344 ph = &h[i].next;
345 }
346
347 *ph = NULL;
348 ph = &header;
349
350 found:
351
352 if (*ph == NULL) {
353 XSRETURN_UNDEF;
354 }
355
356 if ((*ph)->next == NULL) {
357 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len);
378 goto done; 358 goto done;
379 } 359 }
380 360
381 XSRETURN_UNDEF; 361 size = - (ssize_t) (sizeof("; ") - 1);
362
363 for (h = *ph; h; h = h->next) {
364 size += h->value.len + sizeof("; ") - 1;
365 }
366
367 value = ngx_pnalloc(r->pool, size);
368 if (value == NULL) {
369 ctx->error = 1;
370 croak("ngx_pnalloc() failed");
371 }
372
373 p = value;
374
375 for (h = *ph; h; h = h->next) {
376 p = ngx_copy(p, h->value.data, h->value.len);
377
378 if (h->next == NULL) {
379 break;
380 }
381
382 *p++ = sep; *p++ = ' ';
383 }
384
385 ngx_http_perl_set_targ(value, size);
382 386
383 done: 387 done:
384 388
385 ST(0) = TARG; 389 ST(0) = TARG;
386 390