summaryrefslogtreecommitdiffstats
path: root/debian/vendor-h2o/t/50reverse-proxy-drop-headers.t
blob: 0ae1e61ddb786dddd5e2c991865ceba0f21105c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;
use Net::EmptyPort qw(check_port empty_port);
use Test::More;
use t::Util;

plan skip_all => 'curl not found'
    unless prog_exists('curl');
plan skip_all => 'plackup not found'
    unless prog_exists('plackup');
plan skip_all => 'Starlet not found'
    unless system('perl -MStarlet /dev/null > /dev/null 2>&1') == 0;

my $upstream_port = empty_port();

my $guard = spawn_server(
    argv     => [ qw(plackup -s Starlet --keepalive-timeout 100 --access-log /dev/null --listen), "127.0.0.1:$upstream_port", ASSETS_DIR . "/upstream.psgi" ],
    is_ready =>  sub {
        check_port($upstream_port);
    },
);

subtest 'request-header' => sub {
# proxy-authenticate

    my $server = spawn_h2o(<< "EOT");
hosts:
  default:
    paths:
      /:
        proxy.reverse.url: http://127.0.0.1.XIP.IO:$upstream_port
EOT

    my $curl = 'curl --silent --dump-header /dev/stderr';
    my ($headers, $body) = run_prog("$curl"
        . " -H 'Proxy-Authenticate: hoge'"
        . " -H 'Date: Thu, 01 Jan 1970 00:00:00 GMT'"
        . " http://127.0.0.1:@{[$server->{port}]}/echo-headers");
    unlike $body, qr/^proxy-authenticate:/mi, 'proxy-authenticate header should be dropped';
    like $body, qr/^date:/mi, 'date request header is not dropped';
};

subtest 'response header' => sub {
    my $server = spawn_h2o(<< "EOT");
hosts:
  default:
    paths:
      /:
        proxy.reverse.url: http://127.0.0.1.XIP.IO:$upstream_port
EOT

    my $curl = 'curl --silent --dump-header /dev/stderr';
    my ($headers, $body) = run_prog("$curl http://127.0.0.1:@{[$server->{port}]}/fixed-date-header");
    unlike $headers, qr/Thu, 01 Jan 1970 00:00:00 GMT/, "date response header from upstream should be dropped and replaced";
};

done_testing();