@@ -92,6 +92,7 @@ typedef struct {
9292 ngx_str_t _headers ;
9393 ngx_str_t _ca_cart ;
9494 ngx_queue_t * _link_func_locs_queue ;
95+ ngx_array_t * _props ;
9596} ngx_http_link_func_srv_conf_t ;
9697
9798typedef struct {
@@ -206,7 +207,8 @@ void ngx_link_func_log_info(ngx_link_func_ctx_t *ctx, const char* msg);
206207void ngx_link_func_log_warn (ngx_link_func_ctx_t * ctx , const char * msg );
207208void ngx_link_func_log_err (ngx_link_func_ctx_t * ctx , const char * msg );
208209char * ngx_link_func_strdup (ngx_link_func_ctx_t * ctx , const char * src );
209- u_char * ngx_link_func_get_header (ngx_link_func_ctx_t * ctx , const char * key , size_t keylen );
210+ u_char * ngx_link_func_get_header (ngx_link_func_ctx_t * ctx , const char * key , size_t keylen );
211+ u_char * ngx_link_func_get_prop (ngx_link_func_ctx_t * ctx , const char * key , size_t keylen );
210212int ngx_link_func_add_header_in (ngx_link_func_ctx_t * ctx , const char * key , size_t keylen , const char * value , size_t val_len );
211213int ngx_link_func_add_header_out (ngx_link_func_ctx_t * ctx , const char * key , size_t keylen , const char * value , size_t val_len );
212214void * ngx_link_func_get_query_param (ngx_link_func_ctx_t * ctx , const char * key );
@@ -294,6 +296,13 @@ static ngx_command_t ngx_http_link_func_commands[] = {
294296 offsetof(ngx_http_link_func_loc_conf_t , _method_name ), /* No offset when storing the module configuration on struct. */
295297 NULL
296298 },
299+ { ngx_string ("ngx_link_func_add_prop" ),
300+ NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE2 ,
301+ ngx_conf_set_keyval_slot ,
302+ NGX_HTTP_SRV_CONF_OFFSET ,
303+ offsetof(ngx_http_link_func_srv_conf_t , _props ),
304+ NULL
305+ },
297306 ngx_null_command /* command termination */
298307};
299308
@@ -711,7 +720,7 @@ ngx_http_link_func_pre_configuration(ngx_conf_t *cf) {
711720 return NGX_ERROR ;
712721#endif
713722
714- #ifndef ngx_link_func_module_version_31
723+ #ifndef ngx_link_func_module_version_32
715724 ngx_conf_log_error (NGX_LOG_EMERG , cf , 0 , "%s" , "the ngx_http_link_func_module.h might not be latest or not found in the c header path, \
716725 please copy latest ngx_http_link_func_module.h to your /usr/include or /usr/local/include or relavent header search path \
717726 with read and write permission." );
@@ -990,8 +999,8 @@ ngx_http_link_func_create_srv_conf(ngx_conf_t *cf) {
990999static char *
9911000ngx_http_link_func_merge_srv_conf (ngx_conf_t * cf , void * parent , void * child )
9921001{
993- // ngx_http_link_func_srv_conf_t *prev = parent;
994- // ngx_http_link_func_srv_conf_t *conf = child;
1002+ ngx_http_link_func_srv_conf_t * prev = parent ;
1003+ ngx_http_link_func_srv_conf_t * conf = child ;
9951004
9961005
9971006 // ngx_conf_merge_str_value(conf->_libname, prev->_libname, "");
@@ -1010,6 +1019,11 @@ ngx_http_link_func_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
10101019 // "lib_name");
10111020 // return NGX_CONF_ERROR;
10121021 // }
1022+
1023+ if (conf -> _props == NULL ) {
1024+ conf -> _props = prev -> _props ;
1025+ }
1026+
10131027 return NGX_CONF_OK ;
10141028}
10151029
@@ -1659,7 +1673,7 @@ ngx_http_link_func_strdup_with_p(ngx_pool_t *pool, const char *src, size_t len)
16591673}
16601674
16611675u_char *
1662- ngx_link_func_get_header (ngx_link_func_ctx_t * ctx , const char * key , size_t keylen ) {
1676+ ngx_link_func_get_header (ngx_link_func_ctx_t * ctx , const char * key , size_t keylen ) {
16631677 ngx_http_request_t * r = (ngx_http_request_t * )ctx -> __r__ ;
16641678 ngx_list_part_t * part = & r -> headers_in .headers .part ;
16651679 ngx_table_elt_t * header = part -> elts ;
@@ -1685,6 +1699,43 @@ ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char*key, size_t keylen
16851699 }
16861700}
16871701
1702+ u_char *
1703+ ngx_link_func_get_prop (ngx_link_func_ctx_t * ctx , const char * key , size_t keylen ) {
1704+ ngx_http_request_t * r = (ngx_http_request_t * )ctx -> __r__ ;
1705+ ngx_http_link_func_srv_conf_t * scf ;
1706+ ngx_uint_t nelts , i ;
1707+ ngx_keyval_t * keyval ;
1708+
1709+ if (r == NULL ) {
1710+ ngx_log_error (NGX_LOG_EMERG , r -> connection -> log , 0 , "Invalid Session access" );
1711+ return NULL ;
1712+ }
1713+
1714+ scf = ngx_http_get_module_srv_conf (r , ngx_http_link_func_module );
1715+
1716+ if ( scf == NULL ) {
1717+ ngx_log_error (NGX_LOG_EMERG , r -> connection -> log , 0 , "Invalid link function server config" );
1718+ return NULL ;
1719+ }
1720+
1721+ if (scf -> _props == NULL ) {
1722+ return NULL ;
1723+ }
1724+
1725+ nelts = scf -> _props -> nelts ;
1726+ keyval = scf -> _props -> elts ;
1727+
1728+ for (i = 0 ; i < nelts ; i ++ ) {
1729+ if ( keyval -> key .len == keylen && ngx_strncasecmp (keyval -> key .data , (u_char * ) key , keylen ) == 0 ) {
1730+ /** it is config memory pool, should not reallocate or overwrite **/
1731+ return keyval -> value .data ;
1732+ }
1733+ keyval ++ ;
1734+ }
1735+ return NULL ;
1736+ }
1737+
1738+
16881739static int
16891740strpos (const char * haystack , const char * needle ) {
16901741 char * p = ngx_strstr (haystack , needle );
0 commit comments