Permalink
Browse files

fixed Mojo::Client cloning

  • Loading branch information...
1 parent 735d4ab commit 11c493e4f7ebd1bff07bab9ec2c1fa730cccd47e @kraih committed Jan 30, 2011
Showing with 47 additions and 11 deletions.
  1. +1 −0 Changes
  2. +7 −0 lib/Mojo/Client.pm
  3. +39 −11 t/mojo/client.t
View
1 Changes
@@ -34,6 +34,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Fixed small empty route bug.
- Fixed URL merging in Mojo::URL.
- Fixed version detection in Mojolicious::Command::Version.
+ - Fixed Mojo::Client cloning.
- Fixed typos.
1.01 2011-01-06 00:00:00
View
7 lib/Mojo/Client.pm
@@ -296,6 +296,13 @@ sub clone {
my $clone = $self->new;
$clone->app($self->app);
$clone->log($self->log);
+ $clone->on_start($self->on_start);
+ $clone->cert($self->cert);
+ $clone->key($self->key);
+ $clone->http_proxy($self->http_proxy);
+ $clone->https_proxy($self->https_proxy);
+ $clone->no_proxy($self->no_proxy);
+ $clone->user_agent($self->user_agent);
$clone->cookie_jar($self->cookie_jar);
$clone->keep_alive_timeout($self->keep_alive_timeout);
$clone->max_connections($self->max_connections);
View
50 t/mojo/client.t
@@ -9,7 +9,7 @@ BEGIN { $ENV{MOJO_POLL} = 1 }
use Test::More;
plan skip_all => 'Windows is too fragile for this test!'
if $^O eq 'MSWin32' || $^O =~ /cygwin/;
-plan tests => 68;
+plan tests => 80;
use_ok 'Mojo::Client';
@@ -50,23 +50,51 @@ $ENV{http_proxy} = 'proxy.kraih.com';
$ENV{https_proxy} = 'tunnel.kraih.com';
$ENV{no_proxy} = 'localhost,localdomain,foo.com,kraih.com';
$client->detect_proxy;
-is $client->http_proxy, 'proxy.kraih.com', 'right proxy';
-is $client->https_proxy, 'tunnel.kraih.com', 'right proxy';
-is $client->need_proxy('dummy.mojolicio.us'), 1, 'proxy needed';
-is $client->need_proxy('icio.us'), 1, 'proxy needed';
-is $client->need_proxy('localhost'), undef, 'proxy needed';
-is $client->need_proxy('localhost.localdomain'), undef, 'no proxy needed';
-is $client->need_proxy('foo.com'), undef, 'no proxy needed';
-is $client->need_proxy('kraih.com'), undef, 'no proxy needed';
-is $client->need_proxy('www.kraih.com'), undef, 'no proxy needed';
-is $client->need_proxy('www.kraih.com.com'), 1, 'proxy needed';
+my $client2 = $client->clone;
+is $client2->http_proxy, 'proxy.kraih.com', 'right proxy';
+is $client2->https_proxy, 'tunnel.kraih.com', 'right proxy';
+is $client2->need_proxy('dummy.mojolicio.us'), 1, 'proxy needed';
+is $client2->need_proxy('icio.us'), 1, 'proxy needed';
+is $client2->need_proxy('localhost'), undef, 'proxy needed';
+is $client2->need_proxy('localhost.localdomain'), undef, 'no proxy needed';
+is $client2->need_proxy('foo.com'), undef, 'no proxy needed';
+is $client2->need_proxy('kraih.com'), undef, 'no proxy needed';
+is $client2->need_proxy('www.kraih.com'), undef, 'no proxy needed';
+is $client2->need_proxy('www.kraih.com.com'), 1, 'proxy needed';
$ENV{HTTP_PROXY} = $backup;
$ENV{HTTPS_PROXY} = $backup2;
$ENV{NO_PROXY} = $backup3;
$ENV{http_proxy} = $backup4;
$ENV{https_proxy} = $backup5;
$ENV{no_proxy} = $backup6;
+# Cloning
+$client = Mojo::Client->new;
+$client->on_start(sub {23});
+$client->cert('/cert');
+$client->key('/key');
+$client->http_proxy('http://127.0.0.1:3000');
+$client->https_proxy('http://127.0.0.1:4000');
+$client->no_proxy('127.0.0.1');
+$client->user_agent('Trololo');
+$client->keep_alive_timeout(23);
+$client->max_connections(13);
+$client->max_redirects(7);
+$client->websocket_timeout(333);
+$client2 = $client->clone;
+is $client2->on_start, $client->on_start, 'right value';
+is $client2->cert, $client->cert, 'right value';
+is $client2->key, $client->key, 'right value';
+is $client2->http_proxy, $client->http_proxy, 'right value';
+is $client2->https_proxy, $client->https_proxy, 'right value';
+is $client2->no_proxy, $client->no_proxy, 'right value';
+is $client2->user_agent, $client->user_agent, 'right value';
+is $client2->cookie_jar, $client->cookie_jar, 'right value';
+is $client2->keep_alive_timeout, $client->keep_alive_timeout, 'right value';
+is $client2->max_connections, $client->max_connections, 'right value';
+is $client2->max_redirects, $client->max_redirects, 'right value';
+is $client2->websocket_timeout, $client->websocket_timeout, 'right value';
+
# Fresh client
$client = Mojo::Client->singleton->app(app);

0 comments on commit 11c493e

Please sign in to comment.