aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/http/cgi/testdata/test.cgi
blob: a1b2ff893dc5579144ba82f196c8a668ddd81795 (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
#!/usr/bin/perl
# Copyright 2011 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
#
# Test script run as a child process under cgi_test.go

use strict;
use CGI;

my $q = CGI->new;
my $params = $q->Vars;

if ($params->{"loc"}) {
    print "Location: $params->{loc}\r\n\r\n";
    exit(0);
}

my $NL = "\r\n";
$NL = "\n" if $params->{mode} eq "NL";

my $p = sub {
  print "$_[0]$NL";
};

# With carriage returns
$p->("Content-Type: text/html");
$p->("X-Test-Header: X-Test-Value");
$p->("");

print "test=Hello CGI\n";

foreach my $k (sort keys %$params) {
  print "param-$k=$params->{$k}\n";
}

foreach my $k (sort keys %ENV) {
  my $clean_env = $ENV{$k};
  $clean_env =~ s/[\n\r]//g;
  print "env-$k=$clean_env\n";
}