This file is indexed.

/usr/share/perl5/HTTP/Request/Params.pm is in libhttp-request-params-perl 1.02-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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package HTTP::Request::Params;

# $Id: Params.pm,v 1.2 2015/08/11 10:01:12 kiz Exp $
use strict;

=pod

=head1 NAME

HTTP::Request::Params - Retrieve GET/POST Parameters from HTTP Requests

=head1 SYNOPSIS

  use HTTP::Request::Params;
  
  my $http_request = read_request();
  my $parse_params = HTTP::Request::Params->new({
                       req => $http_request,
                     });
  my $params       = $parse_params->params;

=cut

use vars qw[$VERSION];
$VERSION = sprintf '%d.%02d', split m/\./, (qw$Revision: 1.2 $)[1];

use CGI;
use Email::MIME;
use Email::MIME::Modifier;
use Email::MIME::ContentType qw[parse_content_type];
use HTTP::Request;
use HTTP::Message;
use parent qw[Class::Accessor::Fast];

=pod

=head1 DESCRIPTION

This software does all the dirty work of parsing HTTP Requests to find
incoming query parameters.

=head2 new

  my $parser = HTTP::Request::Params->new({
                  req => $http_request,
               });

C<req> - This required argument is either an C<HTTP::Request> object or a
string containing an entier HTTP Request.

Incoming query parameters come from two places. The first place is the
C<query> portion of the URL. Second is the content portion of an HTTP
request as is the case when parsing a POST request, for example.

=head2 params

  my $params = $parser->params;

Returns a hash reference containing all the parameters. The keys in this hash
are the names of the parameters. Values are the values associated with those
parameters in the incoming query. For parameters with multiple values, the value
in this hash will be a list reference. This is the same behaviour as the C<CGI>
module's C<Vars()> function.

=head2 req

  my $req_object = $parser->req;

Returns the C<HTTP::Request> object.

=head2 mime

  my $mime_object = $parser->mime;

Returns the C<Email::MIME> object.

Now, you may be wondering why we're dealing with an C<Email::MIME> object.
The answer is simple. It's an amazing parser for MIME compliant messages,
and RFC 822 compliant messages. When parsing incoming POST data, especially
file uploads, C<Email::MIME> is the perfect fit. It's fast and light.

=cut

sub new {
  my ($class) = shift;
  my $self = $class->SUPER::new(@_);

  if ( not ref( $self->req ) ) {
    $self->req( HTTP::Request->parse( $self->req ) );
  }

  my $message = ( split /\n/, $self->req->as_string, 2 )[1];
  $self->mime( Email::MIME->new( $self->req->as_string ) );

  $self->_find_params;

  return $self;
} ## end sub new

__PACKAGE__->mk_accessors(qw[req mime params]);

sub _find_params {
  my $self         = shift;
  my $query_params = CGI->new( $self->req->url->query )->Vars;
  my $post_params  = {};

  if ( $self->mime->parts > 1 ) {
    foreach my $part ( $self->mime->parts ) {
      next if $part == $self->mime;
      $part->disposition_set('text/plain');    # for easy parsing

      my $disp    = $part->header('Content-Disposition');
      my $ct      = parse_content_type($disp);
      my $name    = $ct->{attributes}->{name};
      my $content = $part->body;

      $content =~ s/\r\n$//;
      $self->_add_to_field( $post_params, $name, $content );
    } ## end foreach my $part ( $self->mime...)
  } else {
    my $body = $self->mime->body;
    chomp $body;
    $post_params = CGI->new($body)->Vars;
  }

  my $params = {};

  # I dislike the use of $_
  for my $k ( keys %{$post_params} ) {
    $self->_add_to_field( $params, $k, $post_params->{$k} );
  }
  for my $k ( keys %{$query_params} ) {
    $self->_add_to_field( $params, $k, $query_params->{$k} );
  }
  $self->params($params);

  return keys %{$params} ? 0 : 1;
} ## end sub _find_params

sub _add_to_field {
  my ( $self, $hash, $name, @content ) = @_;
  my $field = $hash->{$name};
  if ( @content && ref( $content[0] ) ) {
    @content = @{ $content[0] };
  }
  @content = map split(/\0/), @content;

  if ( defined $field ) {
    if ( ref($field) ) {
      push @{$field}, @content;
    } else {
      $field = [ $field, @content ];
    }
  } else {
    if ( @content > 1 ) {
      $field = \@content;
    } else {
      $field = $content[0];
    }
  } ## end else [ if ( defined $field ) ]
  $hash->{$name} = $field;

  return $field ? 1 : 0;
} ## end sub _add_to_field

1;

__END__

=head1 SEE ALSO

C<HTTP::Daemon>,
L<HTTP::Request>,
L<Email::MIME>,
L<CGI>,
L<perl>.

=head1 AUTHOR

Casey West, <F<casey@geeknest.com>>.
Ian Stuart, <F<Ian.Stuart@ed.ac.uk>>.

=head1 COPYRIGHT

  Copyright (c) 2015 Casey West.  All rights reserved.
  This module is free software; you can redistribute it and/or modify it
  under the same terms as Perl itself.

=cut