Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
removed request_timeout attribute from Mojo::UserAgent again
  • Loading branch information
kraih committed Jan 21, 2012
1 parent a1d5947 commit 508cb2a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 45 deletions.
1 change: 0 additions & 1 deletion Changes
@@ -1,7 +1,6 @@
This file documents the revision history for Perl extension Mojolicious.

2.46 2012-01-21 00:00:00
- Added EXPERIMENTAL request_timeout attribute to Mojo::UserAgent.
- Improved documentation.
- Improved tests.
- Fixed small parser bug in Mojo::Message::Response.
Expand Down
31 changes: 3 additions & 28 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -23,7 +23,6 @@ has key => sub { $ENV{MOJO_KEY_FILE} };
has max_connections => 5;
has max_redirects => sub { $ENV{MOJO_MAX_REDIRECTS} || 0 };
has name => 'Mojolicious (Perl)';
has request_timeout => 0;
has transactor => sub { Mojo::UserAgent::Transactor->new };
has websocket_timeout => 300;

Expand Down Expand Up @@ -292,16 +291,8 @@ sub _connected {
my $loop = $self->_loop;
$loop->stream($id)->timeout($self->inactivity_timeout);

# Request timeout
my $c = $self->{connections}->{$id};
my $timeout = $self->request_timeout;
weaken $self;
$c->{timeout} =
$loop->timer($timeout => sub { $self->_error($id, 'Request timeout.') })
if $timeout;

# Store connection information in transaction
my $tx = $c->{tx};
my $tx = $self->{connections}->{$id}->{tx};
$tx->connection($id);
my $handle = $loop->stream($id)->handle;
$tx->local_address($handle->sockhost);
Expand All @@ -310,6 +301,7 @@ sub _connected {
$tx->remote_port($handle->peerport);

# Start writing
weaken $self;
$tx->on(resume => sub { $self->_write($id) });
$self->_write($id);
}
Expand Down Expand Up @@ -369,11 +361,8 @@ sub _finish {
sub _handle {
my ($self, $id, $close) = @_;

# Request timeout
my $c = $self->{connections}->{$id};
$self->_loop->drop($c->{timeout}) if $c->{timeout};

# Finish WebSocket
my $c = $self->{connections}->{$id};
my $old = $c->{tx};
if ($old && $old->is_websocket) {
$self->{processing} -= 1;
Expand Down Expand Up @@ -772,20 +761,6 @@ Value for C<User-Agent> request header, defaults to C<Mojolicious (Perl)>.
Domains that don't require a proxy server to be used.
=head2 C<request_timeout>
my $timeout = $ua->request_timeout;
$ua = $ua->request_timeout(5);
Maximum amount of time in seconds sending the request and receiving the whole
response may take before getting canceled, defaults to C<0>. Setting the
value to C<0> will allow the user agent to wait indefinitely. The timeout
will reset for every followed redirect. Note that this attribute is
EXPERIMENTAL and might change without warning!
# Total limit of 8 seconds
$ua->max_redirects(0)->connect_timeout(3)->request_timeout(5);
=head2 C<transactor>
my $t = $ua->transactor;
Expand Down
17 changes: 1 addition & 16 deletions t/mojolicious/longpolling_lite_app.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher';
}

use Test::More tests => 128;
use Test::More tests => 125;

# "I was God once.
# Yes, I saw. You were doing well until everyone died."
Expand Down Expand Up @@ -416,21 +416,6 @@ $t->get_ok('/finish')->status_is(200)
->header_is('X-Powered-By' => 'Mojolicious (Perl)')->content_is('Finish!');
ok !$finish, 'finish event timing is right';

# GET /too_long (request timeout)
$tx = $t->ua->request_timeout('0.5')->build_tx(GET => '/too_long');
$buffer = '';
$tx->res->body(
sub {
my ($self, $chunk) = @_;
$buffer .= $chunk;
}
);
$t->ua->start($tx);
is $tx->res->code, 200, 'right status';
is $tx->error, 'Request timeout.', 'right error';
is $buffer, 'how', 'right content';
$t->ua->request_timeout(0);

# GET /too_long (inactivity timeout)
$tx = $t->ua->inactivity_timeout('0.5')->build_tx(GET => '/too_long');
$buffer = '';
Expand Down

0 comments on commit 508cb2a

Please sign in to comment.