[PATCH] Proxy: support variables for proxy_method directive

Dmitry Lazurkin dilaz03 at gmail.com
Fri Oct 21 20:53:11 UTC 2016


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');
+
+###############################################################################



More information about the nginx-devel mailing list