/usr/share/perl5/Furl/Request.pm is in libfurl-perl 3.08-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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | package Furl::Request;
use strict;
use warnings;
use utf8;
use Class::Accessor::Lite;
use Furl::Headers;
use Furl::HTTP;
Class::Accessor::Lite->mk_accessors(qw/ method uri protocol headers content /);
sub new {
my $class = shift;
my ($method, $uri, $headers, $content) = @_;
unless (defined $headers) {
$headers = +{};
}
unless (defined $content) {
$content = '';
}
bless +{
method => $method,
uri => $uri,
headers => Furl::Headers->new($headers),
content => $content,
}, $class;
}
sub parse {
my $class = shift;
my $raw_request = shift;
# I didn't use HTTP::Parser::XS for following reasons:
# 1. parse_http_request() function omits request content, but need to deal it.
# 2. this function parses header to PSGI env, but env/header mapping is troublesome.
return unless $raw_request =~ s!^(.+) (.+) (HTTP/1.\d+)\s*!!;
my ($method, $uri, $protocol) = ($1, $2, $3);
my ($header_str, $content) = split /\015?\012\015?\012/, $raw_request, 2;
my $headers = +{};
for (split /\015?\012/, $header_str) {
tr/\015\012//d;
my ($k, $v) = split /\s*:\s*/, $_, 2;
$headers->{lc $k} = $v;
# complete host_port
if (lc $k eq 'host') {
$uri = $v . $uri;
}
}
unless ($uri =~ /^http/) {
$uri = "http://$uri";
}
my $req = $class->new($method, $uri, $headers, $content);
$req->protocol($protocol);
return $req;
}
# alias
*body = \&content;
# shorthand
sub content_length { shift->headers->content_length }
sub content_type { shift->headers->content_type }
sub header { shift->headers->header(@_) }
sub request_line {
my $self = shift;
my $path_query = $self->uri . ''; # for URI.pm
$path_query =~ s!^https?://[^/]+!!;
my $method = $self->method || '';
my $protocol = $self->protocol || '';
return "$method $path_query $protocol";
}
sub as_http_request {
my $self = shift;
require HTTP::Request;
my $req = HTTP::Request->new(
$self->method,
$self->uri,
[ $self->headers->flatten ],
$self->content,
);
$req->protocol($self->protocol);
return $req;
}
sub as_hashref {
my $self = shift;
return +{
method => $self->method,
uri => $self->uri,
protocol => $self->protocol,
headers => [ $self->headers->flatten ],
content => $self->content,
};
}
sub as_string {
my $self = shift;
join("\015\012",
$self->method . ' ' . $self->uri . (defined($self->protocol) ? ' ' . $self->protocol : ''),
$self->headers->as_string,
ref($self->content) =~ qr{\A(?:ARRAY|HASH)\z} ? Furl::HTTP->make_x_www_form_urlencoded($self->content) : $self->content,
);
}
1;
__END__
=head1 NAME
Furl::Request - Request object for Furl
=head1 SYNOPSIS
my $f = Furl->new;
my $req = Furl::Request->new($method, $uri, $headers, $content);
my $res = $f->request($req);
print $req->request_line, "\n";
my $http_req = $req->as_http_request;
my $req_hash = $req->as_hashref;
=head1 DESCRIPTION
This is a HTTP request object in Furl.
=head1 CONSTRUCTOR
my $req = Furl::Request->new($method, $uri);
# or
my $req = Furl::Request->new($method, $uri, \%headers);
# or
my $req = Furl::Request->new($method, $uri, \%headers, $content);
# and
my $req = Furl::Request->parse($http_request_raw_string);
=head1 INSTANCE METHODS
=over 4
=item $req->method($method)
Gets/Sets HTTP request method
=item $req->uri($uri)
Gets/Sets request URI
=item $req->headers($headers)
Gets/Sets instance of L<Furl::Headers>
=item $req->content($content)
=item $req->body($content)
Gets/Sets request body in scalar.
=item $req->protocol($protocol)
$req->protocol('HTTP/1.1');
print $req->protocol; #=> "HTTP/1.1"
Gets/Sets HTTP protocol in string.
=item $req->content_length
=item $req->content_type
=item $req->header
Shorthand to access L<Furl::Headers>.
=item $req->as_http_request
Make instance of L<HTTP::Request> from L<Furl::Request>.
=item $req->as_hashref
Convert request object to HashRef.
Format is following:
method: Str
uri: Str
protocol: Str
headers: ArrayRef[Str]
content: Str
=item $req->request_line
print $req->request_line; #=> "GET / HTTP/1.1"
Returns HTTP request line.
=back
|