[PATCH] Upstream: support named location for X-Accel-Redirect

Toshikuni Fukaya toshikuni-fukaya at cybozu.co.jp
Tue Nov 11 00:33:00 UTC 2014


Hi,

(2014/11/11 3:02), Maxim Dounin wrote:
> Hello!
>
> On Tue, Nov 04, 2014 at 08:18:44PM +0900, Toshikuni Fukaya wrote:
>
>> # HG changeset patch
>> # User Toshikuni Fukaya <toshikuni-fukaya at cybozu.co.jp>
>> # Date 1415098583 -32400
>> # Node ID 6f4517db02a8cd4068b9378bd93fe6290f54720d
>> # Parent  dff86e2246a53b0f4a61935cd5c8c0a0f66d0ca2
>> Upstream: support named location for X-Accel-Redirect.
>>
>> diff -r dff86e2246a5 -r 6f4517db02a8 src/http/ngx_http_upstream.c
>> --- a/src/http/ngx_http_upstream.c	Mon Aug 25 13:41:31 2014 +0400
>> +++ b/src/http/ngx_http_upstream.c	Tue Nov 04 19:56:23 2014 +0900
>> @@ -2218,19 +2218,25 @@
>>           }
>>
>>           uri = u->headers_in.x_accel_redirect->value;
>> -        ngx_str_null(&args);
>> -        flags = NGX_HTTP_LOG_UNSAFE;
>> -
>> -        if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags) != NGX_OK) {
>> -            ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
>> -            return NGX_DONE;
>> -        }
>> -
>> -        if (r->method != NGX_HTTP_HEAD) {
>> -            r->method = NGX_HTTP_GET;
>> -        }
>> -
>> -        ngx_http_internal_redirect(r, &uri, &args);
>> +
>> +        if (uri.len > 0 && uri.data[0] == '@') {
>> +            ngx_http_named_location(r, &uri);
>> +        } else {
>> +            ngx_str_null(&args);
>> +            flags = NGX_HTTP_LOG_UNSAFE;
>
>
> The uri here is required to be null-terminated, so the uri.len
> check can be safely dropped.  With this and an extra line added as
> per style:
>
> diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
> --- a/src/http/ngx_http_upstream.c
> +++ b/src/http/ngx_http_upstream.c
> @@ -2219,8 +2219,9 @@ ngx_http_upstream_process_headers(ngx_ht
>
>           uri = u->headers_in.x_accel_redirect->value;
>
> -        if (uri.len > 0 && uri.data[0] == '@') {
> +        if (uri.data[0] == '@') {
>               ngx_http_named_location(r, &uri);
> +
>           } else {
>               ngx_str_null(&args);
>               flags = NGX_HTTP_LOG_UNSAFE;
>
>
> Please let me know if looks good for you.
>

It's good. Thanks a lot for explanation of nginx internals.

>> +
>> +            if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags) != NGX_OK) {
>> +                ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
>> +                return NGX_DONE;
>> +            }
>> +
>> +            if (r->method != NGX_HTTP_HEAD) {
>> +                r->method = NGX_HTTP_GET;
>> +            }
>> +
>> +            ngx_http_internal_redirect(r, &uri, &args);
>> +        }
>> +
>>           ngx_http_finalize_request(r, NGX_DONE);
>>           return NGX_DONE;
>>       }
>>
>> _______________________________________________
>> nginx-devel mailing list
>> nginx-devel at nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>

Toshikuni Fukaya



More information about the nginx-devel mailing list