/usr/share/perl5/Plack/HTTPParser/PP.pm is in libplack-perl 0.9985-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | package Plack::HTTPParser::PP;
use strict;
use warnings;
use URI::Escape;
sub parse_http_request {
my($chunk, $env) = @_;
$env ||= {};
# pre-header blank lines are allowed (RFC 2616 4.1)
$chunk =~ s/^(\x0d?\x0a)+//;
return -2 unless length $chunk;
# double line break indicates end of header; parse it
if ($chunk =~ /^(.*?\x0d?\x0a\x0d?\x0a)/s) {
return _parse_header($chunk, length $1, $env);
}
return -2; # still waiting for unknown amount of header lines
}
sub _parse_header {
my($chunk, $eoh, $env) = @_;
my $header = substr($chunk, 0, $eoh,'');
$chunk =~ s/^\x0d?\x0a\x0d?\x0a//;
# parse into lines
my @header = split /\x0d?\x0a/,$header;
my $request = shift @header;
# join folded lines
my @out;
for(@header) {
if(/^[ \t]+/) {
return -1 unless @out;
$out[-1] .= $_;
} else {
push @out, $_;
}
}
# parse request or response line
my $obj;
my ($major, $minor);
my ($method,$uri,$http) = split / /,$request;
return -1 unless $http and $http =~ /^HTTP\/(\d+)\.(\d+)$/i;
($major, $minor) = ($1, $2);
$env->{REQUEST_METHOD} = $method;
$env->{SERVER_PROTOCOL} = "HTTP/$major.$minor";
$env->{REQUEST_URI} = $uri;
my($path, $query) = ( $uri =~ /^([^?]*)(?:\?(.*))?$/s );
for ($path, $query) { s/\#.*$// if defined && length } # dumb clients sending URI fragments
$env->{PATH_INFO} = URI::Escape::uri_unescape($path);
$env->{QUERY_STRING} = $query || '';
$env->{SCRIPT_NAME} = '';
# import headers
my $token = qr/[^][\x00-\x1f\x7f()<>@,;:\\"\/?={} \t]+/;
my $k;
for my $header (@out) {
if ( $header =~ s/^($token): ?// ) {
$k = $1;
$k =~ s/-/_/g;
$k = uc $k;
if ($k !~ /^(?:CONTENT_LENGTH|CONTENT_TYPE)$/) {
$k = "HTTP_$k";
}
} elsif ( $header =~ /^\s+/) {
# multiline header
} else {
return -1;
}
if (exists $env->{$k}) {
$env->{$k} .= ", $header";
} else {
$env->{$k} = $header;
}
}
return $eoh;
}
1;
__END__
=head1 NAME
Plack::HTTPParser::PP - Pure perl fallback of HTTP::Parser::XS
=head1 DESCRIPTION
Do not use this module directly. Use L<Plack::HTTPParser> instead.
=head1 AUTHOR
Tatsuhiko Miyagawa
=cut
|