view proxy-xar.t @ 107:1c0ec30614c6

Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks. TEST_GLOBALS replaces previously used -g switch. This allows tests to be executed on 0.6.* branch. For compatibility with old tests -g switch will be used if TEST_GLOBALS wasn't expaneded in config. TEST_GLOBALS_HTTP replaces multiple variables (access_log, root, client_body_temp_path, proxy_temp_path, fastcgi_temp_path) previously specified directly in test configs. This change reduce duplication and allows tests to be used with nginx compiled without fastcgi and/or proxy modules (as proxy_temp_path and fastcgi_temp_path are added conditionally).
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 14 Oct 2009 02:23:52 +0400
parents a2fc9b9e9a2b
children 8ac1faaddd2c
line wrap: on
line source

#!/usr/bin/perl

# (C) Maxim Dounin

# Tests for proxy X-Accel-Redirect functionality.

###############################################################################

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('rewrite')->plan(8);

$t->write_file_expand('nginx.conf', <<'EOF');

%%TEST_GLOBALS%%

master_process off;
daemon         off;

events {
}

http {
    %%TEST_GLOBALS_HTTP%%

    server {
        listen       127.0.0.1:8080;
        server_name  localhost;

        location /proxy {
            proxy_pass http://127.0.0.1:8080/return-xar;
        }
        location /return-xar {
            add_header  X-Accel-Redirect     /index.html;

            # this headers will be preserved on
            # X-Accel-Redirect

            add_header  Content-Type         text/blah;
            add_header  Set-Cookie           blah=blah;
            add_header  Content-Disposition  attachment;
            add_header  Cache-Control        no-cache;
            add_header  Expires              fake;
            add_header  Accept-Ranges        parrots;

            # others won't be
            add_header  Something            other;

            return 204;
        }
    }
}

EOF

$t->write_file('index.html', 'SEE-THIS');
$t->run();

###############################################################################

my $r = http_get('/proxy');
like($r, qr/SEE-THIS/, 'X-Accel-Redirect works');
like($r, qr/^Content-Type: text\/blah/m, 'Content-Type preserved');
like($r, qr/^Set-Cookie: blah=blah/m, 'Set-Cookie preserved');
like($r, qr/^Content-Disposition: attachment/m, 'Content-Disposition preserved');
like($r, qr/^Cache-Control: no-cache/m, 'Cache-Control preserved');
like($r, qr/^Expires: fake/m, 'Expires preserved');
like($r, qr/^Accept-Ranges: parrots/m, 'Accept-Ranges preserved');
unlike($r, qr/^Something/m, 'other headers stripped');

###############################################################################