Furl

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

      (kazuho)

2.19 2013-08-26T02:10:09Z

    - Testing fix for Starlet >= 0.20.
      force response HTTP/1.0. Starlet >= 0.20 support HTTP/1.1
      (kazeburo)

2.18 2013-08-08T07:11:30Z

    - Furl::Response::decoded_content returns undef if user specifies
      'Accept-Encoding' for data compression. Because content is already
      inflated, so HTTP::Message::decoded_content failed and return undef.
      (syohex)

2.17 2013-07-01T03:11:49Z

    - Fix Furl::Request#as_string the request contains ARRAY or HASH.
      (tokuhirom)

2.16 2013-05-22T07:48:21Z

    - Fix timeout problem(#56) on recent Linux(3.8 or later)

Changes  view on Meta::CPAN

      Internal response. It's compatible with LWP.
      (tokuhirom)

2.03 2013-02-09T18:17:13

    - Support URL based authorization.
      Both Proxy-Authorization and Basic Authorization.

2.02 2013-02-06T17:25:11

    - Added Furl::Response#decoded_content
      (xaicron++)
    - Added Furl::Headers#clone
      (tokuhirom)

2.01 2013-01-23T19:17:47


    - pass SSL_verifycn_name on connecting ssl over proxy.
      IO::Socket::SSL detects host name from PeerHost, but it can't when user
      is using proxy.

lib/Furl/Response.pm  view on Meta::CPAN

sub body   { shift->content() }

# shorthand
sub content_length   { shift->headers->content_length() }
sub content_type     { shift->headers->content_type() }
sub content_encoding { shift->headers->content_encoding() }
sub header           { shift->headers->header(@_) }

sub protocol { "HTTP/1." . $_[0]->{minor_version} }

sub decoded_content {
    my $self = shift;
    my $cloned = $self->headers->clone;

    # 'HTTP::Message::decoded_content' tries to decompress content
    # if response header contains 'Content-Encoding' field.
    # However 'Furl' decompresses content by itself, 'Content-Encoding' field
    # whose value is supported encoding type should be removed from response header.
    my @removed = grep { ! m{\b(?:gzip|x-gzip|deflate)\b} } $cloned->header('content-encoding');
    $cloned->header('content-encoding', \@removed);

    $self->_as_http_response_internal([ $cloned->flatten ])->decoded_content(@_);
}

sub as_http_response {
    my ($self) = @_;
    return $self->_as_http_response_internal([ $self->headers->flatten ])
}

sub _as_http_response_internal {
    my ($self, $flatten_headers) = @_;

lib/Furl/Response.pm  view on Meta::CPAN


sub is_success { substr( $_[0]->code, 0, 1 ) eq '2' }
sub status_line { $_[0]->code . ' ' . $_[0]->message }

sub charset {
    my $self = shift;

    return $self->{__charset} if exists $self->{__charset};
    if ($self->can('content_charset')){
        # To suppress:
        # Parsing of undecoded UTF-8 will give garbage when decoding entities
        local $SIG{__WARN__} = sub {};
        my $charset = $self->content_charset;
        $self->{__charset} = $charset;
        return $charset;
    }

    my $content_type = $self->headers->header('Content-Type');
    return unless $content_type;
    $content_type =~ /charset=([A-Za-z0-9_\-]+)/io;
    $self->{__charset} = $1 || undef;

lib/Furl/Response.pm  view on Meta::CPAN

=item $res->headers

Returns instance of L<Furl::Headers>

=item $res->content

=item $res->body

Returns response body in scalar.

=item $res->decoded_content

This will return the content after any C<< Content-Encoding >> and charsets have been decoded. See L<< HTTP::Message >> for details

=item $res->request

Returns instance of L<Furl::Request> related this response.

=item $res->content_length

=item $res->content_type

=item $res->content_encoding

t/100_low/13_deflate.t  view on Meta::CPAN

                    $furl->request(
                        url        => "http://127.0.0.1:$port/",
                        write_code => sub { $content .= $_[3] },
                    );
                is $code, 200, "request()";
                is Furl::HTTP::_header_get($headers, 'content-encoding'), $encoding;
                is($content, $CONTENT) or do { require Devel::Peek; Devel::Peek::Dump($content) };
            }

            for(1 .. $n){
                note "decoded_content $_";
                my $res = Furl->new(
                    headers => ['Accept-Encoding' => $encoding]
                )->get("http://127.0.0.1:$port/");

                ok defined($res->decoded_content);
            }
        }

        done_testing;
    },
    server => sub {
        my $port = shift;
        Slowloris::Server->new( port => $port )->run(
            Plack::Middleware::Deflater->wrap(
                sub {

t/400_components/001_response-coding/01-file.t  view on Meta::CPAN

#}

my $httpd = run_http_server {
    my $req = shift;
    my $path = 't/400_components/001_response-coding' . $req->uri->path;
    open my $fh, '<', $path or die "$path: $!";
    return [ 200, [ 'Content-Type' => 'text/html' ], $fh ];
};
note $httpd->host_port;

for my $meth (qw/charset encoder encoding decoded_content/){
    can_ok('Furl::Response', $meth);
}

my %charset = qw(
		 UTF-8        utf-8-strict;
		 EUC-JP       EUC-JP
		 Shift_JIS    SHIFT_JIS
		 ISO-2022-JP  ISO-2022-JP
	       );

t/400_components/02_response.t  view on Meta::CPAN

            content-type text/html
            x-foo yay
            x-bar hoge
            content-length 9
            content-encoding chunked
        )]
    );
    is_deeply($dat->[2], ['hit man']);
};

subtest decoded_content => sub {
    my $res = Furl::Response->new(
        1, 200, 'OK',
        +{
            'content-type' => ['text/plain; charset=UTF-8'],
        },
        "\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212",
    );
    is $res->decoded_content, "\x{3042}\x{3044}\x{3046}\x{3048}\x{304a}";
};

subtest 'as_string' => sub {
    my $res = Furl::Response->new(
        1, 200, 'OK',
        +{
            'x-foo'            => ['yay'],
            'x-bar'            => ['hoge'],
            'content-length'   => [9],
            'content-type'     => ['text/html'],



( run in 0.308 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )