@@ -12,6 +12,7 @@ static ngx_conf_enum_t ngx_http_redirectionio_enable_state[] = {
1212static void * ngx_http_redirectionio_create_conf (ngx_conf_t * cf );
1313static char * ngx_http_redirectionio_merge_conf (ngx_conf_t * cf , void * parent , void * child );
1414static char * ngx_http_redirectionio_set_url (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
15+ static char * ngx_http_redirectionio_set_header (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
1516
1617static ngx_int_t ngx_http_redirectionio_postconfiguration (ngx_conf_t * cf );
1718
@@ -85,6 +86,14 @@ static ngx_command_t ngx_http_redirectionio_commands[] = {
8586 offsetof(ngx_http_redirectionio_conf_t , host ),
8687 NULL
8788 },
89+ {
90+ ngx_string ("redirectionio_set_header" ),
91+ NGX_HTTP_MAIN_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_SIF_CONF |NGX_HTTP_LOC_CONF |NGX_HTTP_LIF_CONF |NGX_CONF_TAKE2 ,
92+ ngx_http_redirectionio_set_header ,
93+ NGX_HTTP_LOC_CONF_OFFSET ,
94+ offsetof(ngx_http_redirectionio_conf_t , headers_set ),
95+ NULL
96+ },
8897 ngx_null_command /* command termination */
8998};
9099
@@ -401,13 +410,20 @@ static void *ngx_http_redirectionio_create_conf(ngx_conf_t *cf) {
401410 conf -> server .min_conns = RIO_MIN_CONNECTIONS ;
402411 conf -> server .max_conns = RIO_MAX_CONNECTIONS ;
403412 conf -> server .max_conns = RIO_MAX_CONNECTIONS ;
413+ conf -> server .timeout = RIO_DEFAULT_TIMEOUT ;
414+
415+ if (ngx_array_init (& conf -> headers_set , cf -> pool , 10 , sizeof (ngx_http_redirectionio_header_set_t )) != NGX_OK ) {
416+ return NGX_CONF_ERROR ;
417+ }
404418
405419 return conf ;
406420}
407421
408422static char * ngx_http_redirectionio_merge_conf (ngx_conf_t * cf , void * parent , void * child ) {
409423 ngx_http_redirectionio_conf_t * prev = parent ;
410424 ngx_http_redirectionio_conf_t * conf = child ;
425+ ngx_uint_t i ;
426+ ngx_http_redirectionio_header_set_t * phs , * hs ;
411427
412428 ngx_conf_merge_uint_value (conf -> enable_logs , prev -> enable_logs , NGX_HTTP_REDIRECTIONIO_ON );
413429 ngx_conf_merge_uint_value (conf -> show_rule_ids , prev -> show_rule_ids , NGX_HTTP_REDIRECTIONIO_OFF );
@@ -424,6 +440,15 @@ static char *ngx_http_redirectionio_merge_conf(ngx_conf_t *cf, void *parent, voi
424440 conf -> host = prev -> host ;
425441 }
426442
443+ phs = prev -> headers_set .elts ;
444+
445+ for (i = 0 ; i < prev -> headers_set .nelts ; i ++ ) {
446+ hs = ngx_array_push (& conf -> headers_set );
447+
448+ hs -> name = phs [i ].name ;
449+ hs -> value = phs [i ].value ;
450+ }
451+
427452 if (conf -> server .pass .url .data == NULL ) {
428453 if (prev -> server .pass .url .data ) {
429454 conf -> server .pass = prev -> server .pass ;
@@ -477,7 +502,6 @@ static char *ngx_http_redirectionio_merge_conf(ngx_conf_t *cf, void *parent, voi
477502 ngx_conf_merge_uint_value (conf -> enable , prev -> enable , NGX_HTTP_REDIRECTIONIO_OFF );
478503 }
479504
480-
481505 return NGX_CONF_OK ;
482506}
483507
@@ -561,16 +585,72 @@ static char *ngx_http_redirectionio_set_url(ngx_conf_t *cf, ngx_command_t *cmd,
561585 return NGX_CONF_ERROR ;
562586}
563587
588+ static char * ngx_http_redirectionio_set_header (ngx_conf_t * cf , ngx_command_t * cmd , void * conf ) {
589+ char * p = conf ;
590+ ngx_array_t * headers_set ;
591+ ngx_str_t * value ;
592+ ngx_http_redirectionio_header_set_t * h ;
593+ ngx_http_compile_complex_value_t ccvk , ccvv ;
594+
595+ headers_set = (ngx_array_t * ) (p + cmd -> offset );
596+ h = ngx_array_push (headers_set );
597+
598+ if (h == NULL ) {
599+ return NGX_CONF_ERROR ;
600+ }
601+
602+ h -> name = ngx_palloc (cf -> pool , sizeof (ngx_http_complex_value_t ));
603+
604+ if (h -> name == NULL ) {
605+ return NGX_CONF_ERROR ;
606+ }
607+
608+ h -> value = ngx_palloc (cf -> pool , sizeof (ngx_http_complex_value_t ));
609+
610+ if (h -> value == NULL ) {
611+ return NGX_CONF_ERROR ;
612+ }
613+
614+ value = cf -> args -> elts ;
615+
616+ ngx_memzero (& ccvk , sizeof (ngx_http_compile_complex_value_t ));
617+ ngx_memzero (& ccvv , sizeof (ngx_http_compile_complex_value_t ));
618+
619+ ccvk .cf = cf ;
620+ ccvk .value = & value [1 ];
621+ ccvk .complex_value = h -> name ;
622+
623+ ccvv .cf = cf ;
624+ ccvv .value = & value [2 ];
625+ ccvv .complex_value = h -> value ;
626+
627+ if (ngx_http_compile_complex_value (& ccvk ) != NGX_OK ) {
628+ ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 , "invalid parameter \"%V\"" , & value [1 ]);
629+
630+ return NGX_CONF_ERROR ;
631+ }
632+
633+ if (ngx_http_compile_complex_value (& ccvv ) != NGX_OK ) {
634+ ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 , "invalid parameter \"%V\"" , & value [2 ]);
635+
636+ return NGX_CONF_ERROR ;
637+ }
638+
639+ return NGX_CONF_OK ;
640+ }
641+
564642static void ngx_http_redirectionio_write_match_action_handler (ngx_event_t * wev ) {
565643 ngx_http_redirectionio_ctx_t * ctx ;
566644 ngx_connection_t * c ;
567645 ngx_http_request_t * r ;
646+ ngx_http_redirectionio_conf_t * conf ;
568647
569648 c = wev -> data ;
570649 r = c -> data ;
571650 ctx = ngx_http_get_module_ctx (r , ngx_http_redirectionio_module );
651+ conf = ngx_http_get_module_loc_conf (r , ngx_http_redirectionio_module );
572652
573- ngx_add_timer (c -> read , RIO_DEFAULT_TIMEOUT );
653+ ngx_add_timer (c -> read , conf -> server . timeout );
574654 ctx -> read_handler = ngx_http_redirectionio_read_match_action_handler ;
575655
576656 ngx_http_redirectionio_protocol_send_match (c , r , ctx , & ctx -> project_key );
0 commit comments