[PATCH] [PATCH] Proxy: support variables for proxy_method directive

Dmitry Lazurkin dilaz03 at gmail.com
Fri Oct 28 13:07:52 UTC 2016


Hello, Maxim.

Thank you! (:

On 10/26/2016 08:32 PM, Maxim Dounin wrote:
> Hello!
>
> On Sat, Oct 22, 2016 at 12:31:16AM +0300, dilaz03 at gmail.com wrote:
>
>> # HG changeset patch
>> # User Dmitry Lazurkin <dilaz03 at gmail.com>
>> # Date 1476631441 -10800
>> #      Sun Oct 16 18:24:01 2016 +0300
>> # Node ID 9fbfc0ccb28e1eee624ff212de88fa1c051f09d9
>> # Parent  56d6bfe6b609c565a9f500bde573fd9b488ff960
>> Proxy: support variables for proxy_method directive.
>>
>> diff -r 56d6bfe6b609 -r 9fbfc0ccb28e src/http/modules/ngx_http_proxy_module.c
>> --- a/src/http/modules/ngx_http_proxy_module.c	Fri Oct 21 16:28:39 2016 +0300
>> +++ b/src/http/modules/ngx_http_proxy_module.c	Sun Oct 16 18:24:01 2016 +0300
>> @@ -73,7 +73,7 @@
>>      ngx_array_t                   *cookie_domains;
>>      ngx_array_t                   *cookie_paths;
>>  
>> -    ngx_str_t                      method;
>> +    ngx_http_complex_value_t      *method;
>>      ngx_str_t                      location;
>>      ngx_str_t                      url;
>>  
>> @@ -380,7 +380,7 @@
>>  
>>      { ngx_string("proxy_method"),
>>        NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
>> -      ngx_conf_set_str_slot,
>> +      ngx_http_set_complex_value_slot,
>>        NGX_HTTP_LOC_CONF_OFFSET,
>>        offsetof(ngx_http_proxy_loc_conf_t, method),
>>        NULL },
>> @@ -1159,8 +1159,10 @@
>>          /* HEAD was changed to GET to cache response */
>>          method = u->method;
>>  
>> -    } else if (plcf->method.len) {
>> -        method = plcf->method;
>> +    } else if (plcf->method != NULL) {
>> +        if (ngx_http_complex_value(r, plcf->method, &method) != NGX_OK) {
>> +            return NGX_ERROR;
>> +        }
>>  
>>      } else {
>>          method = r->method_name;
>> @@ -3158,7 +3160,9 @@
>>  
>>  #endif
>>  
>> -    ngx_conf_merge_str_value(conf->method, prev->method, "");
>> +    if (conf->method == NULL) {
>> +        conf->method = prev->method;
>> +    }
>>  
>>      ngx_conf_merge_value(conf->upstream.pass_request_headers,
>>                                prev->upstream.pass_request_headers, 1);
> Looks good, except a few style nits:
>
> - We don't usually check pointers with "!= NULL", just testing 
>   "if (plcf->method)" would be enough here.
>
> - You've forgot to update the "set by ngx_pcalloc()" comment in 
>   ngx_http_proxy_create_loc_conf().
>
> Committed with the following patch on top:
>
> --- a/src/http/modules/ngx_http_proxy_module.c
> +++ b/src/http/modules/ngx_http_proxy_module.c
> @@ -1159,7 +1159,7 @@ ngx_http_proxy_create_request(ngx_http_r
>          /* HEAD was changed to GET to cache response */
>          method = u->method;
>  
> -    } else if (plcf->method != NULL) {
> +    } else if (plcf->method) {
>          if (ngx_http_complex_value(r, plcf->method, &method) != NGX_OK) {
>              return NGX_ERROR;
>          }
> @@ -2799,7 +2799,7 @@ ngx_http_proxy_create_loc_conf(ngx_conf_
>       *     conf->upstream.store_values = NULL;
>       *     conf->upstream.ssl_name = NULL;
>       *
> -     *     conf->method = { 0, NULL };
> +     *     conf->method = NULL;
>       *     conf->headers_source = NULL;
>       *     conf->headers.lengths = NULL;
>       *     conf->headers.values = NULL;
>
> Thanks!
>




More information about the nginx-devel mailing list