comparison src/http/modules/ngx_http_userid_filter_module.c @ 8024:ef6a3a99a81a

Reworked multi headers to use linked lists. Multi headers are now using linked lists instead of arrays. Notably, the following fields were changed: r->headers_in.cookies (renamed to r->headers_in.cookie), r->headers_in.x_forwarded_for, r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control u->headers_in.cookies (renamed to u->headers_in.set_cookie). The r->headers_in.cookies and u->headers_in.cookies fields were renamed to r->headers_in.cookie and u->headers_in.set_cookie to match header names. The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines() functions were changed accordingly. With this change, multi headers are now essentially equivalent to normal headers, and following changes will further make them equivalent.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 May 2022 21:25:33 +0300
parents c0cacad62cc8
children
comparison
equal deleted inserted replaced
8023:08b3ea81ff5f 8024:ef6a3a99a81a
317 317
318 318
319 static ngx_http_userid_ctx_t * 319 static ngx_http_userid_ctx_t *
320 ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_conf_t *conf) 320 ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_conf_t *conf)
321 { 321 {
322 ngx_int_t n; 322 ngx_str_t src, dst;
323 ngx_str_t src, dst; 323 ngx_table_elt_t *cookie;
324 ngx_table_elt_t **cookies; 324 ngx_http_userid_ctx_t *ctx;
325 ngx_http_userid_ctx_t *ctx;
326 325
327 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); 326 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module);
328 327
329 if (ctx) { 328 if (ctx) {
330 return ctx; 329 return ctx;
337 } 336 }
338 337
339 ngx_http_set_ctx(r, ctx, ngx_http_userid_filter_module); 338 ngx_http_set_ctx(r, ctx, ngx_http_userid_filter_module);
340 } 339 }
341 340
342 n = ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &conf->name, 341 cookie = ngx_http_parse_multi_header_lines(r, r->headers_in.cookie,
343 &ctx->cookie); 342 &conf->name, &ctx->cookie);
344 if (n == NGX_DECLINED) { 343 if (cookie == NULL) {
345 return ctx; 344 return ctx;
346 } 345 }
347 346
348 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 347 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
349 "uid cookie: \"%V\"", &ctx->cookie); 348 "uid cookie: \"%V\"", &ctx->cookie);
350 349
351 if (ctx->cookie.len < 22) { 350 if (ctx->cookie.len < 22) {
352 cookies = r->headers_in.cookies.elts;
353 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 351 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
354 "client sent too short userid cookie \"%V\"", 352 "client sent too short userid cookie \"%V\"",
355 &cookies[n]->value); 353 &cookie->value);
356 return ctx; 354 return ctx;
357 } 355 }
358 356
359 src = ctx->cookie; 357 src = ctx->cookie;
360 358
368 src.len = 22; 366 src.len = 22;
369 367
370 dst.data = (u_char *) ctx->uid_got; 368 dst.data = (u_char *) ctx->uid_got;
371 369
372 if (ngx_decode_base64(&dst, &src) == NGX_ERROR) { 370 if (ngx_decode_base64(&dst, &src) == NGX_ERROR) {
373 cookies = r->headers_in.cookies.elts;
374 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 371 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
375 "client sent invalid userid cookie \"%V\"", 372 "client sent invalid userid cookie \"%V\"",
376 &cookies[n]->value); 373 &cookie->value);
377 return ctx; 374 return ctx;
378 } 375 }
379 376
380 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 377 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
381 "uid: %08XD%08XD%08XD%08XD", 378 "uid: %08XD%08XD%08XD%08XD",