[PATCH] Proxy: support variables for proxy_method directive

Maxim Dounin mdounin at mdounin.ru
Wed Oct 26 17:38:05 UTC 2016


Hello!

On Fri, Oct 21, 2016 at 11:53:11PM +0300, Dmitry Lazurkin wrote:

> Add more tests.
> 
> # HG changeset patch
> # User Dmitry Lazurkin <dilaz03 at gmail.com>
> # Date 1476632999 -10800
> #      Sun Oct 16 18:49:59 2016 +0300
> # Node ID 916ac83eed31a4e7f6f303e28867b925fc62bc27
> # Parent  1b11a12be17913a75e81d318dcb6b912eac5f29e
> Tests: add tests for proxy_method directive.
> 
> diff -r 1b11a12be179 -r 916ac83eed31 proxy_method.t
> --- /dev/null    Thu Jan 01 00:00:00 1970 +0000
> +++ b/proxy_method.t    Sun Oct 16 18:49:59 2016 +0300
> @@ -0,0 +1,86 @@
> +#!/usr/bin/perl
> +
> +# (C) Dmitry Lazurkin
> +
> +# Tests for proxy_method.
> +
> +###############################################################################
> +
> +use warnings;
> +use strict;
> +
> +use Test::More;
> +
> +BEGIN { use FindBin; chdir($FindBin::Bin); }
> +
> +use lib 'lib';
> +use Test::Nginx;
> +
> +###############################################################################
> +
> +select STDERR; $| = 1;
> +select STDOUT; $| = 1;
> +
> +my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(4)
> +    ->write_file_expand('nginx.conf', <<'EOF');
> +
> +%%TEST_GLOBALS%%
> +
> +daemon off;
> +
> +events {
> +}
> +
> +http {
> +    %%TEST_GLOBALS_HTTP%%
> +
> +    server {
> +        listen       127.0.0.1:8080;
> +        server_name  localhost;
> +
> +        location /preserve {
> +            proxy_pass http://127.0.0.1:8080/get-method;
> +        }
> +
> +        location /const {
> +            proxy_pass http://127.0.0.1:8080/get-method;
> +            proxy_method POST;
> +        }
> +
> +        location /var {
> +            proxy_pass http://127.0.0.1:8080/get-method;
> +            proxy_method $arg_method;
> +        }
> +
> +        location /parent {
> +            proxy_method POST;
> +            location /parent/child {
> +                proxy_pass http://127.0.0.1:8080/get-method;
> +            }
> +        }
> +
> +        location /get-method {
> +            return 200 "request_method=$request_method";
> +        }
> +    }
> +}
> +
> +EOF
> +
> +$t->run();
> +
> +###############################################################################
> +
> +like(http_get('/preserve'), qr/request_method=GET/,
> +     'proxy_method from request');
> +
> +like(http_get('/const'), qr/request_method=POST/,
> +     'proxy_method from constant');
> +
> +like(http_get('/var?method=POST'), qr/request_method=POST/,
> +     'proxy_method from variable');
> +
> +like(http_get('/parent/child'), qr/request_method=POST/,
> +     'proxy_method from parent');
> +
> +###############################################################################

Such a test will fail on versions without variables support in 
proxy_method.  This is a problem, as the same test suite is used 
to test both mainline and stable.  To address this we use 
conditional TODO tests with version checked:

diff --git a/proxy_method.t b/proxy_method.t
--- a/proxy_method.t
+++ b/proxy_method.t
@@ -77,9 +77,14 @@ like(http_get('/preserve'), qr/request_m
 like(http_get('/const'), qr/request_method=POST/,
      'proxy_method from constant');
 
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.11.6');
+
 like(http_get('/var?method=POST'), qr/request_method=POST/,
      'proxy_method from variable');
 
+}
+
 like(http_get('/parent/child'), qr/request_method=POST/,
      'proxy_method from parent');

Additionally, style is slighly different in our test scripts for 
historical reasons, tabs are used to indent perl code.
 
Committed with the above changes, thanks.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list