Commit | Line | Data |
b3029f84 |
1 | #!/usr/bin/perl |
1b64d24d |
2 | |
1b64d24d |
3 | # echo-perl -- |
4 | # |
5 | # Produce a page containing all FastCGI inputs |
6 | # |
7 | # Copyright (c) 1996 Open Market, Inc. |
8 | # |
af1b4cad |
9 | # See the file "LICENSE" for information on usage and redistribution |
1b64d24d |
10 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
11 | # |
48cdf763 |
12 | # $Id: echo.PL,v 1.2 2000/12/14 13:46:23 skimo Exp $ |
1b64d24d |
13 | # |
14 | # Changed by skimo to demostrate autoflushing 1997/02/19 |
15 | # |
16 | |
17 | use FCGI; |
48cdf763 |
18 | use strict; |
1b64d24d |
19 | |
20 | sub print_env { |
21 | my($label, $envp) = @_; |
22 | print("$label:<br>\n<pre>\n"); |
23 | my @keys = sort keys(%$envp); |
48cdf763 |
24 | foreach my $key (@keys) { |
1b64d24d |
25 | print("$key=$$envp{$key}\n"); |
26 | } |
27 | print("</pre><p>\n"); |
28 | } |
29 | |
48cdf763 |
30 | my %env; |
31 | my $req = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%env); |
32 | my $count = 0; |
33 | while($req->Accept() >= 0) { |
1b64d24d |
34 | print("Content-type: text/html\r\n\r\n", |
35 | "<title>FastCGI echo (Perl)</title>\n", |
36 | "<h1>FastCGI echo (Perl)</h1>\n", |
37 | "Request number ", ++$count, "<p>\n"); |
48cdf763 |
38 | my $len = 0 + $env{'CONTENT_LENGTH'}; |
1b64d24d |
39 | if($len == 0) { |
40 | print("No data from standard input.<p>\n"); |
41 | } else { |
42 | print("Standard input:<br>\n<pre>\n"); |
48cdf763 |
43 | for(my $i = 0; $i < $len; $i++) { |
44 | my $ch = getc(STDIN); |
1b64d24d |
45 | if($ch eq "") { |
46 | print("Error: Not enough bytes received ", |
47 | "on standard input<p>\n"); |
48 | last; |
49 | } |
50 | print($ch); |
51 | } |
52 | print("\n</pre><p>\n"); |
53 | } |
48cdf763 |
54 | print_env("Request environment", \%env); |
1b64d24d |
55 | print "More on its way ... wait a few seconds\n<BR>\n<BR>"; |
48cdf763 |
56 | $req->Flush(); |
1b64d24d |
57 | sleep(3); |
48cdf763 |
58 | print_env("Initial environment", \%ENV); |
59 | $req->Finish(); |
1b64d24d |
60 | } |