@@ -40,7 +40,7 @@ static ngx_command_t ngx_http_redirectionio_commands[] = {
4040 {
4141 ngx_string ("redirectionio_project_key" ),
4242 NGX_HTTP_MAIN_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_SIF_CONF |NGX_HTTP_LOC_CONF |NGX_HTTP_LIF_CONF |NGX_CONF_TAKE1 ,
43- ngx_conf_set_str_slot ,
43+ ngx_http_set_complex_value_slot ,
4444 NGX_HTTP_LOC_CONF_OFFSET ,
4545 offsetof(ngx_http_redirectionio_conf_t , project_key ),
4646 NULL
@@ -72,11 +72,19 @@ static ngx_command_t ngx_http_redirectionio_commands[] = {
7272 {
7373 ngx_string ("redirectionio_scheme" ),
7474 NGX_HTTP_MAIN_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_SIF_CONF |NGX_HTTP_LOC_CONF |NGX_HTTP_LIF_CONF |NGX_CONF_TAKE1 ,
75- ngx_conf_set_str_slot ,
75+ ngx_http_set_complex_value_slot ,
7676 NGX_HTTP_LOC_CONF_OFFSET ,
7777 offsetof(ngx_http_redirectionio_conf_t , scheme ),
7878 NULL
7979 },
80+ {
81+ ngx_string ("redirectionio_host" ),
82+ NGX_HTTP_MAIN_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_SIF_CONF |NGX_HTTP_LOC_CONF |NGX_HTTP_LIF_CONF |NGX_CONF_TAKE1 ,
83+ ngx_http_set_complex_value_slot ,
84+ NGX_HTTP_LOC_CONF_OFFSET ,
85+ offsetof(ngx_http_redirectionio_conf_t , host ),
86+ NULL
87+ },
8088 ngx_null_command /* command termination */
8189};
8290
@@ -198,6 +206,21 @@ static ngx_int_t ngx_http_redirectionio_create_ctx_handler(ngx_http_request_t *r
198206 ctx -> wait_for_connection = 0 ;
199207 ctx -> last_buffer_sent = 0 ;
200208 ctx -> read_handler = ngx_http_redirectionio_read_dummy_handler ;
209+ ctx -> project_key .len = 0 ;
210+ ctx -> scheme .len = 0 ;
211+ ctx -> host .len = 0 ;
212+
213+ if (ngx_http_complex_value (r , conf -> project_key , & ctx -> project_key ) != NGX_OK ) {
214+ return NGX_DECLINED ;
215+ }
216+
217+ if (conf -> scheme != NULL && ngx_http_complex_value (r , conf -> scheme , & ctx -> scheme ) != NGX_OK ) {
218+ return NGX_DECLINED ;
219+ }
220+
221+ if (conf -> host != NULL && ngx_http_complex_value (r , conf -> host , & ctx -> host ) != NGX_OK ) {
222+ return NGX_DECLINED ;
223+ }
201224
202225 ngx_http_set_ctx (r , ctx , ngx_http_redirectionio_module );
203226
@@ -329,7 +352,7 @@ static ngx_int_t ngx_http_redirectionio_log_handler(ngx_http_request_t *r) {
329352 return NGX_DECLINED ;
330353 }
331354
332- log = ngx_http_redirectionio_protocol_create_log (r , ctx , & conf -> project_key );
355+ log = ngx_http_redirectionio_protocol_create_log (r , ctx , & ctx -> project_key );
333356
334357 if (log == NULL ) {
335358 return NGX_DECLINED ;
@@ -363,8 +386,18 @@ static char *ngx_http_redirectionio_merge_conf(ngx_conf_t *cf, void *parent, voi
363386
364387 ngx_conf_merge_uint_value (conf -> enable_logs , prev -> enable_logs , NGX_HTTP_REDIRECTIONIO_ON );
365388 ngx_conf_merge_uint_value (conf -> show_rule_ids , prev -> show_rule_ids , NGX_HTTP_REDIRECTIONIO_OFF );
366- ngx_conf_merge_str_value (conf -> project_key , prev -> project_key , "" );
367- ngx_conf_merge_str_value (conf -> scheme , prev -> scheme , "" );
389+
390+ if (conf -> project_key == NULL ) {
391+ conf -> project_key = prev -> project_key ;
392+ }
393+
394+ if (conf -> scheme == NULL ) {
395+ conf -> scheme = prev -> scheme ;
396+ }
397+
398+ if (conf -> host == NULL ) {
399+ conf -> host = prev -> host ;
400+ }
368401
369402 if (conf -> pass .url .data == NULL ) {
370403 if (prev -> pass .url .data ) {
@@ -413,7 +446,7 @@ static char *ngx_http_redirectionio_merge_conf(ngx_conf_t *cf, void *parent, voi
413446 }
414447 }
415448
416- if (conf -> project_key . len > 0 ) {
449+ if (conf -> project_key != NULL ) {
417450 ngx_conf_merge_uint_value (conf -> enable , prev -> enable , NGX_HTTP_REDIRECTIONIO_ON );
418451 } else {
419452 ngx_conf_merge_uint_value (conf -> enable , prev -> enable , NGX_HTTP_REDIRECTIONIO_OFF );
@@ -456,17 +489,15 @@ static void ngx_http_redirectionio_write_match_action_handler(ngx_event_t *wev)
456489 ngx_http_redirectionio_ctx_t * ctx ;
457490 ngx_connection_t * c ;
458491 ngx_http_request_t * r ;
459- ngx_http_redirectionio_conf_t * conf ;
460492
461493 c = wev -> data ;
462494 r = c -> data ;
463495 ctx = ngx_http_get_module_ctx (r , ngx_http_redirectionio_module );
464- conf = ngx_http_get_module_loc_conf (r , ngx_http_redirectionio_module );
465496
466497 ngx_add_timer (c -> read , RIO_TIMEOUT );
467498 ctx -> read_handler = ngx_http_redirectionio_read_match_action_handler ;
468499
469- ngx_http_redirectionio_protocol_send_match (c , r , ctx , & conf -> project_key );
500+ ngx_http_redirectionio_protocol_send_match (c , r , ctx , & ctx -> project_key );
470501}
471502
472503static void ngx_http_redirectionio_read_match_action_handler (ngx_event_t * rev , const char * action_serialized ) {
0 commit comments