@@ -311,18 +311,17 @@ static ngx_str_t ngx_http_uploadprogress_jsonp_multiple_defaults[] = {
311311static ngx_array_t ngx_http_uploadprogress_global_templates ;
312312
313313static ngx_str_t *
314- get_tracking_id (ngx_http_request_t * r )
314+ get_tracking_id_internal (ngx_http_request_t * r , ngx_str_t * header_ref , const char * caller , bool multi )
315315{
316316 u_char * p , * start_p ;
317317 ngx_uint_t i ;
318318 ngx_list_part_t * part ;
319319 ngx_table_elt_t * header ;
320320 ngx_str_t * ret , args ;
321- ngx_http_uploadprogress_conf_t * upcf ;
322321
323- upcf = ngx_http_get_module_loc_conf ( r , ngx_http_uploadprogress_module ) ;
322+ ( void ) multi ;
324323
325- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 , "upload-progress: get_tracking_id" );
324+ ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 , "upload-progress: %s" , caller );
326325
327326 part = & r -> headers_in .headers .part ;
328327 header = part -> elts ;
@@ -340,19 +339,19 @@ get_tracking_id(ngx_http_request_t * r)
340339 }
341340
342341 if (
343- header [i ].key .len == upcf -> header . len &&
344- ngx_strncasecmp (header [i ].key .data , upcf -> header . data , header [i ].key .len ) == 0
342+ header [i ].key .len == header_ref -> len &&
343+ ngx_strncasecmp (header [i ].key .data , header_ref -> data , header [i ].key .len ) == 0
345344 ) {
346345 ret = ngx_calloc (sizeof (ngx_str_t ), r -> connection -> log );
347346 * ret = header [i ].value ;
348347 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
349- "upload-progress: get_tracking_id found header: %V" , ret );
348+ "upload-progress: %s: found header: %V" , caller , ret );
350349 return ret ;
351350 }
352351 }
353352
354353 ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
355- "upload-progress: get_tracking_id no header found" );
354+ "upload-progress: %s: no header found" , caller );
356355
357356 /* not found, check as a request arg */
358357 /* it is possible the request args have not been yet created (or already released) */
@@ -361,26 +360,26 @@ get_tracking_id(ngx_http_request_t * r)
361360
362361 if (args .len && args .data ) {
363362 ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
364- "upload-progress: get_tracking_id no header found, args found" );
363+ "upload-progress: %s: no header found, args found" , caller );
365364 i = 0 ;
366365 p = args .data ;
367366 do {
368367 ngx_uint_t len = args .len - (p - args .data );
369368 if (
370- len >= (upcf -> header . len + 1 ) &&
371- ngx_strncasecmp (p , upcf -> header . data , upcf -> header . len ) == 0 &&
372- p [upcf -> header . len ] == '='
369+ len >= (header_ref -> len + 1 ) &&
370+ ngx_strncasecmp (p , header_ref -> data , header_ref -> len ) == 0 &&
371+ p [header_ref -> len ] == '='
373372 ) {
374373 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
375- "upload-progress: get_tracking_id found args: %s" ,p );
374+ "upload-progress: %s: found args: %s" , caller , p );
376375 i = 1 ;
377376 break ;
378377 }
379378 p ++ ;
380379 } while (len > 0 );
381380
382381 if (i ) {
383- start_p = p += upcf -> header . len + 1 ;
382+ start_p = p += header_ref -> len + 1 ;
384383 while (p < args .data + args .len ) {
385384 if (* (++ p ) == '&' ) {
386385 break ;
@@ -391,105 +390,34 @@ get_tracking_id(ngx_http_request_t * r)
391390 ret -> data = start_p ;
392391 ret -> len = p - start_p ;
393392 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
394- "upload-progress: get_tracking_id found args: %V" ,ret );
393+ "upload-progress: %s: found args: %V" , caller , ret );
395394 return ret ;
396395 }
397396 }
398397
399398 ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
400- "upload-progress: get_tracking_id no id found" );
399+ "upload-progress: %s: no id found" , caller );
401400 return NULL ;
402401}
403402
404403static ngx_str_t *
405- get_tracking_ids_mul (ngx_http_request_t * r )
404+ get_tracking_id (ngx_http_request_t * r )
406405{
407- u_char * p , * start_p ;
408- ngx_uint_t i ;
409- ngx_list_part_t * part ;
410- ngx_table_elt_t * header ;
411- ngx_str_t * ret , args ;
412- ngx_http_uploadprogress_conf_t * upcf ;
406+ ngx_http_uploadprogress_conf_t * upcf ;
413407
414408 upcf = ngx_http_get_module_loc_conf (r , ngx_http_uploadprogress_module );
415409
416- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 , "upload-progress: get_tracking_ids" );
417-
418- part = & r -> headers_in .headers .part ;
419- header = part -> elts ;
420-
421- for (i = 0 ; /* void */ ; i ++ ) {
422-
423- if (i >= part -> nelts ) {
424- if (part -> next == NULL ) {
425- break ;
426- }
427-
428- part = part -> next ;
429- header = part -> elts ;
430- i = 0 ;
431- }
432-
433- if (
434- header [i ].key .len == upcf -> header_mul .len &&
435- ngx_strncasecmp (header [i ].key .data , upcf -> header_mul .data , header [i ].key .len ) == 0
436- ) {
437- ret = ngx_calloc (sizeof (ngx_str_t ), r -> connection -> log );
438- * ret = header [i ].value ;
439- ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
440- "upload-progress: get_tracking_ids found header: %V" , ret );
441- return ret ;
442- }
443- }
444-
445- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
446- "upload-progress: get_tracking_ids no header found" );
447-
448- /* not found, check as a request arg */
449- /* it is possible the request args have not been yet created (or already released) */
450- /* so let's try harder first from the request line */
451- args = r -> args ;
452-
453- if (args .len && args .data ) {
454- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
455- "upload-progress: get_tracking_id no header found, args found" );
456- i = 0 ;
457- p = args .data ;
458- do {
459- ngx_uint_t len = args .len - (p - args .data );
460- if (
461- len >= (upcf -> header_mul .len + 1 ) &&
462- ngx_strncasecmp (p , upcf -> header_mul .data , upcf -> header_mul .len ) == 0 &&
463- p [upcf -> header_mul .len ] == '='
464- ) {
465- ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
466- "upload-progress: get_tracking_id found args: %s" ,p );
467- i = 1 ;
468- break ;
469- }
470- p ++ ;
471- } while (len > 0 );
410+ return get_tracking_id_internal (r , & upcf -> header , "get_tracking_id" , false);
411+ }
472412
473- if (i ) {
474- start_p = p += upcf -> header_mul .len + 1 ;
475- while (p < args .data + args .len ) {
476- if (* (++ p ) == '&' ) {
477- break ;
478- }
479- }
413+ static ngx_str_t *
414+ get_tracking_ids_mul (ngx_http_request_t * r )
415+ {
416+ ngx_http_uploadprogress_conf_t * upcf ;
480417
481- ret = ngx_calloc (sizeof (ngx_str_t ), r -> connection -> log );
482- ret -> data = start_p ;
483- ret -> len = p - start_p ;
484- ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
485- "upload-progress: get_tracking_id found args: %V" ,ret );
486- return ret ;
487- }
488- }
418+ upcf = ngx_http_get_module_loc_conf (r , ngx_http_uploadprogress_module );
489419
490- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
491- "upload-progress: get_tracking_id no id found" );
492- return NULL ;
420+ return get_tracking_id_internal (r , & upcf -> header_mul , "get_tracking_ids_mul" , true);
493421}
494422
495423static ngx_http_uploadprogress_node_t *
0 commit comments