Commit | Line | Data |
0198fd3c |
1 | #!./perl |
2 | # |
3 | # echo-perl -- |
4 | # |
5 | # Produce a page containing all FastCGI inputs |
6 | # |
7 | # Copyright (c) 1996 Open Market, Inc. |
8 | # |
9 | # See the file "LICENSE.TERMS" for information on usage and redistribution |
10 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
11 | # |
12 | # $Id: echo-perl,v 1.1 1997/09/16 15:36:28 stanleyg Exp $ |
13 | # |
14 | |
15 | use FCGI; |
16 | |
17 | sub print_env { |
18 | my($label, $envp) = @_; |
19 | print("$label:<br>\n<pre>\n"); |
20 | my @keys = sort keys(%$envp); |
21 | foreach $key (@keys) { |
22 | print("$key=$$envp{$key}\n"); |
23 | } |
24 | print("</pre><p>\n"); |
25 | } |
26 | |
27 | while (($key, $val) = each %ENV) { |
28 | $initialEnv{$key} = $val; |
29 | } |
30 | $count = 0; |
31 | while(FCGI::accept() >= 0) { |
32 | print("Content-type: text/html\r\n\r\n", |
33 | "<title>FastCGI echo (Perl)</title>\n", |
34 | "<h1>FastCGI echo (Perl)</h1>\n", |
35 | "Request number ", ++$count, "<p>\n"); |
36 | $len = 0 + $ENV{'CONTENT_LENGTH'}; |
37 | if($len == 0) { |
38 | print("No data from standard input.<p>\n"); |
39 | } else { |
40 | print("Standard input:<br>\n<pre>\n"); |
41 | for($i = 0; $i < $len; $i++) { |
42 | $ch = getc(STDIN); |
43 | if($ch eq "") { |
44 | print("Error: Not enough bytes received ", |
45 | "on standard input<p>\n"); |
46 | last; |
47 | } |
48 | print($ch); |
49 | } |
50 | print("\n</pre><p>\n"); |
51 | } |
52 | print_env("Request environment", \%ENV); |
53 | print_env("Initial environment", \%initialEnv); |
54 | } |