[PATCH] Tests: add tests for proxy_method directive

Dmitry Lazurkin dilaz03 at gmail.com
Mon Oct 17 17:10:03 UTC 2016


# HG changeset patch
# User Dmitry Lazurkin <dilaz03 at gmail.com>
# Date 1476632999 -10800
#      Sun Oct 16 18:49:59 2016 +0300
# Node ID b3e2d294bf908a33be87e641bbb1879aaf5e1fa2
# Parent  8c5ba361b416227d547c456ff1e4a1f6f117736b
Tests: add tests for proxy_method directive.

diff -r 8c5ba361b416 -r b3e2d294bf90 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,79 @@
+#!/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(3)
+	->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 /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('/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