| 1 |
wakaba |
1.1 |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
use strict; |
| 4 |
|
|
my $self = q(/~wakaba/-temp/test/http/encode/encoded.cgi); |
| 5 |
|
|
my $mode = $main::ENV{PATH_INFO}; |
| 6 |
|
|
|
| 7 |
|
|
my $src_hdr = <<EOH; |
| 8 |
|
|
Content-Type: text/html |
| 9 |
|
|
EOH |
| 10 |
|
|
my $src = <<EOH; |
| 11 |
|
|
<!DOCTYPE html SYSTEM> |
| 12 |
|
|
<html> |
| 13 |
|
|
<p>Test (@{[escape($mode)]}) success!</p> |
| 14 |
|
|
<dl> |
| 15 |
|
|
<dt>Your Accept CE:</dt><dd>@{[escape($ENV{HTTP_ACCEPT_ENCODING})]}</dd> |
| 16 |
|
|
<dt>Your Accept TE:</dt><dd>@{[escape($ENV{HTTP_TE})]}</dd> |
| 17 |
|
|
</dl> |
| 18 |
|
|
<ul> |
| 19 |
|
|
<li><a href="$self/-/identity/">identity</a></li> |
| 20 |
|
|
<li><a href="$self/content/gzip/">ce:gzip</a></li> |
| 21 |
|
|
<li><a href="$self/transfer/gzip/">te:gzip</a></li> |
| 22 |
|
|
<li><a href="$self/content/x-gzip/">ce:x-gzip</a></li> |
| 23 |
|
|
<li><a href="$self/transfer/x-gzip/">te:x-gzip</a></li> |
| 24 |
|
|
|
| 25 |
|
|
<li><a href="$self/content/deflate/">ce:deflate</a></li> |
| 26 |
|
|
<li><a href="$self/transfer/deflate/">te:deflate</a></li> |
| 27 |
|
|
<li><a href="$self/content/x-deflate/">ce:x-deflate</a></li> |
| 28 |
|
|
<li><a href="$self/transfer/x-deflate/">te:x-deflate</a></li> |
| 29 |
|
|
|
| 30 |
|
|
<li><a href="$self/content/compress/">ce:compress</a></li> |
| 31 |
|
|
<li><a href="$self/transfer/compress/">te:compress</a></li> |
| 32 |
|
|
<li><a href="$self/content/x-compress/">ce:x-compress</a></li> |
| 33 |
|
|
<li><a href="$self/transfer/x-compress/">te:x-compress</a></li> |
| 34 |
|
|
|
| 35 |
|
|
<li><a href="$self/content/bzip/">ce:bzip</a></li> |
| 36 |
|
|
<li><a href="$self/transfer/bzip/">te:bzip</a></li> |
| 37 |
|
|
<li><a href="$self/content/x-bzip/">ce:x-bzip</a></li> |
| 38 |
|
|
<li><a href="$self/transfer/x-bzip/">te:x-bzip</a></li> |
| 39 |
|
|
<li><a href="$self/content/bzip2/">ce:bzip2</a></li> |
| 40 |
|
|
<li><a href="$self/transfer/bzip2/">te:bzip2</a></li> |
| 41 |
|
|
<li><a href="$self/content/x-bzip2/">ce:x-bzip2</a></li> |
| 42 |
|
|
<li><a href="$self/transfer/x-bzip2/">te:x-bzip2</a></li> |
| 43 |
|
|
|
| 44 |
|
|
<li><a href="$self/transfer/gzip-deflate/">te:gzip,deflate</a></li> |
| 45 |
|
|
<li><a href="$self/transfer/gzip-chunked/">te:gzip,chunked</a></li> |
| 46 |
|
|
<li><a href="$self/transfer/chunked-gzip/">te:chunked,gzip</a></li> |
| 47 |
|
|
<li><a href="$self/transfer/chunked-gzip-chunked/">te:chunked,gzip,chunked</a></li> |
| 48 |
|
|
<li><a href="$self/transfer/chunked-chunked/">te:chunked,chunked</a></li> |
| 49 |
|
|
|
| 50 |
|
|
<li><a href="$self/transfer/chunked/">te:chunked:crlf</a></li> |
| 51 |
|
|
<li><a href="$self/transfer/chunked/cr/">te:chunked:cr</a></li> |
| 52 |
|
|
<li><a href="$self/transfer/chunked/lf/">te:chunked:lf</a></li> |
| 53 |
|
|
<li><a href="$self/transfer/chunked/param/">te:chunked;param</a></li> |
| 54 |
|
|
<li><a href="$self/transfer/chunked/trailer/">te:chunked,trailer</a></li> |
| 55 |
|
|
|
| 56 |
|
|
<li><a href="$self/content/x-unknown/">ce:x-unknown</a></li> |
| 57 |
|
|
<li><a href="$self/transfer/x-unknown/">te:x-unknown</a></li> |
| 58 |
|
|
|
| 59 |
|
|
</ul> |
| 60 |
|
|
</html> |
| 61 |
|
|
EOH |
| 62 |
|
|
|
| 63 |
|
|
sub escape ($) { |
| 64 |
|
|
my $s = shift; |
| 65 |
|
|
$s =~ s/&/&/ge; |
| 66 |
|
|
$s =~ s/</</ge; |
| 67 |
|
|
$s =~ s/>/>/ge; |
| 68 |
|
|
$s =~ s/"/"/ge; |
| 69 |
|
|
$s; |
| 70 |
|
|
} |
| 71 |
|
|
|
| 72 |
|
|
if ($mode =~ /gzip-deflate/) { |
| 73 |
|
|
require Compress::Zlib; |
| 74 |
|
|
$src = Compress::Zlib::compress(Compress::Zlib::memGzip ($src)); |
| 75 |
|
|
print $src_hdr; |
| 76 |
|
|
print qq(Transfer-Encoding: gzip,deflate\n); |
| 77 |
|
|
print "\n"; |
| 78 |
|
|
print $src; |
| 79 |
|
|
} elsif ($mode =~ /chunked-gzip-chunked/) { |
| 80 |
|
|
require Compress::Zlib; |
| 81 |
|
|
$src = Compress::Zlib::memGzip (sprintf ('%X',length($src))."\x0D\x0A".$src."\x0D\x0A0\x0D\x0A\x0D\x0A"); |
| 82 |
|
|
print $src_hdr; |
| 83 |
|
|
print qq(Transfer-Encoding: gzip,chunked\n); |
| 84 |
|
|
print "\n"; |
| 85 |
|
|
print sprintf ('%X',length($src))."\x0D\x0A".$src."\x0D\x0A0\x0D\x0A\x0D\x0A"; |
| 86 |
|
|
} elsif ($mode =~ /gzip-chunked/) { |
| 87 |
|
|
require Compress::Zlib; |
| 88 |
|
|
$src = Compress::Zlib::memGzip ($src); |
| 89 |
|
|
print $src_hdr; |
| 90 |
|
|
print qq(Transfer-Encoding: gzip,chunked\n); |
| 91 |
|
|
print "\n"; |
| 92 |
|
|
print sprintf ('%X',length($src))."\x0D\x0A".$src."\x0D\x0A0\x0D\x0A\x0D\x0A"; |
| 93 |
|
|
} elsif ($mode =~ /gzip-chunked/) { |
| 94 |
|
|
require Compress::Zlib; |
| 95 |
|
|
$src = Compress::Zlib::memGzip (sprintf ('%X',length($src))."\x0D\x0A".$src."\x0D\x0A0\x0D\x0A\x0D\x0A"); |
| 96 |
|
|
print $src_hdr; |
| 97 |
|
|
print qq(Transfer-Encoding: gzip,chunked\n); |
| 98 |
|
|
print "\n"; |
| 99 |
|
|
print $src; |
| 100 |
|
|
} elsif ($mode =~ /gzip/) { |
| 101 |
|
|
require Compress::Zlib; |
| 102 |
|
|
$src = Compress::Zlib::memGzip ($src); |
| 103 |
|
|
print $src_hdr; |
| 104 |
|
|
my $e = 'gzip'; |
| 105 |
|
|
$e = 'x-gzip' if $mode =~ /x-gzip/; |
| 106 |
|
|
if ($mode !~ /transfer/) { |
| 107 |
|
|
print qq(Content-Encoding: $e\n); |
| 108 |
|
|
} else { |
| 109 |
|
|
print qq(Transfer-Encoding: $e\n); |
| 110 |
|
|
} |
| 111 |
|
|
print "\n"; |
| 112 |
|
|
print $src; |
| 113 |
|
|
} elsif ($mode =~ /deflate/) { |
| 114 |
|
|
require Compress::Zlib; |
| 115 |
|
|
$src = Compress::Zlib::compress ($src); |
| 116 |
|
|
print $src_hdr; |
| 117 |
|
|
my $e = 'deflate'; |
| 118 |
|
|
$e = 'x-deflate' if $mode =~ /x-deflate/; |
| 119 |
|
|
if ($mode !~ /transfer/) { |
| 120 |
|
|
print qq(Content-Encoding: $e\n); |
| 121 |
|
|
} else { |
| 122 |
|
|
print qq(Transfer-Encoding: $e\n); |
| 123 |
|
|
} |
| 124 |
|
|
print "\n"; |
| 125 |
|
|
print $src; |
| 126 |
|
|
} elsif ($mode =~ /bzip/) { |
| 127 |
|
|
print $src_hdr; |
| 128 |
|
|
my $e = 'bzip'; |
| 129 |
|
|
$e .= '2' if $mode =~ /bzip2/; |
| 130 |
|
|
$e = 'x-'.$e if $mode =~ /x-bzip/; |
| 131 |
|
|
if ($mode !~ /transfer/) { |
| 132 |
|
|
print qq(Content-Encoding: $e\n); |
| 133 |
|
|
} else { |
| 134 |
|
|
print qq(Transfer-Encoding: $e\n); |
| 135 |
|
|
} |
| 136 |
|
|
print "\n"; |
| 137 |
|
|
open BZ, "| bzip2"; |
| 138 |
|
|
print BZ $src; |
| 139 |
|
|
while (<>) { |
| 140 |
|
|
print; |
| 141 |
|
|
} |
| 142 |
|
|
close BZ; |
| 143 |
|
|
} elsif ($mode =~ /compress/) { |
| 144 |
|
|
print $src_hdr; |
| 145 |
|
|
my $e = 'compress'; |
| 146 |
|
|
$e = 'x-'.$e if $mode =~ /x-compress/; |
| 147 |
|
|
if ($mode !~ /transfer/) { |
| 148 |
|
|
print qq(Content-Encoding: $e\n); |
| 149 |
|
|
} else { |
| 150 |
|
|
print qq(Transfer-Encoding: $e\n); |
| 151 |
|
|
} |
| 152 |
|
|
print "\n"; |
| 153 |
|
|
open BZ, "| compress"; |
| 154 |
|
|
print BZ $src; |
| 155 |
|
|
while (<>) { |
| 156 |
|
|
print; |
| 157 |
|
|
} |
| 158 |
|
|
close BZ; |
| 159 |
|
|
} elsif ($mode =~ /deflate/) { |
| 160 |
|
|
print $src_hdr; |
| 161 |
|
|
if ($mode !~ /transfer/) { |
| 162 |
|
|
print qq(Content-Encoding: x-unknown\n); |
| 163 |
|
|
} else { |
| 164 |
|
|
print qq(Transfer-Encoding: x-unknown\n); |
| 165 |
|
|
} |
| 166 |
|
|
print "\n"; |
| 167 |
|
|
print $src; |
| 168 |
|
|
} elsif ($mode =~ /chunked-chunked/) { |
| 169 |
|
|
print $src_hdr; |
| 170 |
|
|
print qq(Transfer-Encoding: chunked,chunked |
| 171 |
|
|
|
| 172 |
|
|
); |
| 173 |
|
|
$src = sprintf ('%X',length($src))."\x0D\x0A".$src."\x0D\x0A0\x0D\x0A\x0D\x0A"; |
| 174 |
|
|
print sprintf ('%X',length($src))."\x0D\x0A".$src."\x0D\x0A0\x0D\x0A\x0D\x0A"; |
| 175 |
|
|
} elsif ($mode =~ /chunked/) { |
| 176 |
|
|
print $src_hdr; |
| 177 |
|
|
my $nl = $mode =~ m!/cr/! ? "\x0D" : $mode =~ m!/lf/! ? "\x0A" : "\x0D\x0A"; |
| 178 |
|
|
my $param = ""; |
| 179 |
|
|
$param = "; x-param".$nl if $mode =~ m!/param/!; |
| 180 |
|
|
print qq(Transfer-Encoding: chunked |
| 181 |
|
|
|
| 182 |
|
|
@{[sprintf '%X', length($src)]}).$nl.$param; |
| 183 |
|
|
print $src.$nl; |
| 184 |
|
|
print q(0).$nl.$param; |
| 185 |
|
|
print "Some-Header: test".$nl if $mode =~ /trailer/; |
| 186 |
|
|
print $nl; |
| 187 |
|
|
} else { # identity |
| 188 |
|
|
print $src_hdr; |
| 189 |
|
|
print "\n"; |
| 190 |
|
|
print $src; |
| 191 |
|
|
} |