Rename Perl -> perl (gotta move all the files).
[catagits/fcgi2.git] / perl / echo.PL
1 use Config;
2
3 open OUT, ">echo.fpl";
4 print OUT "#!$Config{perlpath}\n";
5 print OUT while <DATA>;
6 close OUT;
7 chmod 0755, "echo.fpl";
8 __END__
9 #
10 #  echo-perl --
11
12 #       Produce a page containing all FastCGI inputs
13
14 # Copyright (c) 1996 Open Market, Inc.
15 #
16 # See the file "LICENSE.TERMS" for information on usage and redistribution
17 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
18
19 #  $Id: echo.PL,v 1.1 1999/02/13 05:26:47 roberts Exp $
20 #
21 # Changed by skimo to demostrate autoflushing 1997/02/19
22 #
23
24 use FCGI;
25
26 sub print_env {
27     my($label, $envp) = @_;
28     print("$label:<br>\n<pre>\n");
29     my @keys = sort keys(%$envp);
30     foreach $key (@keys) {
31         print("$key=$$envp{$key}\n");
32     }
33     print("</pre><p>\n");
34 }
35
36 while (($key, $val) = each %ENV) {
37     $initialEnv{$key} = $val;
38 }
39 $count = 0;
40 while(FCGI::accept() >= 0) {
41     print("Content-type: text/html\r\n\r\n",
42           "<title>FastCGI echo (Perl)</title>\n",
43           "<h1>FastCGI echo (Perl)</h1>\n",
44           "Request number ", ++$count, "<p>\n");
45     $len = 0 + $ENV{'CONTENT_LENGTH'};
46     if($len == 0) {
47         print("No data from standard input.<p>\n");
48     } else {
49         print("Standard input:<br>\n<pre>\n");
50         for($i = 0; $i < $len; $i++) {
51             $ch = getc(STDIN);
52             if($ch eq "") {
53                 print("Error: Not enough bytes received ",
54                       "on standard input<p>\n");
55                 last;
56             }
57             print($ch);
58         }
59         print("\n</pre><p>\n");
60     }
61     print_env("Request environment", \%ENV);
62     print "More on its way ... wait a few seconds\n<BR>\n<BR>";
63     FCGI::flush();
64     sleep(3);
65     print_env("Initial environment", \%initialEnv);
66 }