Navigation Menu

Skip to content

Commit

Permalink
fixed a few small redirect and proxy connect bugs in Mojo::UserAgent:…
Browse files Browse the repository at this point in the history
…:Transactor
  • Loading branch information
kraih committed Apr 22, 2013
1 parent f972dea commit 1daaa72
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -9,6 +9,8 @@
- Fixed small html_unescape bug in Mojo::Util.
- Fixed small encoding bug in routes command.
- Fixed a few small clone bugs.
- Fixed a few small redirect and proxy connect bugs in
Mojo::UserAgent::Transactor.

3.95 2013-04-12
- Added finished_ok method to Test::Mojo.
Expand Down
16 changes: 7 additions & 9 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -73,7 +73,7 @@ sub proxy_connect {

# Already a CONNECT request
my $req = $old->req;
return undef if $req->method eq 'CONNECT';
return undef if uc $req->method eq 'CONNECT';

# No proxy
return undef unless my $proxy = $req->proxy;
Expand Down Expand Up @@ -106,7 +106,7 @@ sub redirect {
# Clone request if necessary
my $new = Mojo::Transaction::HTTP->new;
my $req = $old->req;
my $method = $req->method;
my $method = uc $req->method;
if (grep { $_ eq $code } 301, 307, 308) {
return undef unless my $req = $req->clone;
$new->req($req);
Expand Down Expand Up @@ -182,16 +182,14 @@ sub _form {
my $parts = $self->_multipart($options{charset}, $form);
$req->content(
Mojo::Content::MultiPart->new(headers => $headers, parts => $parts));
return $tx;
}

# Urlencoded
else {
$headers->content_type('application/x-www-form-urlencoded');
my $p = Mojo::Parameters->new(map { $_ => $form->{$_} } sort keys %$form);
$p->charset($options{charset}) if defined $options{charset};
$req->body($p->to_string);
}

$headers->content_type('application/x-www-form-urlencoded');
my $p = Mojo::Parameters->new(map { $_ => $form->{$_} } sort keys %$form);
$p->charset($options{charset}) if defined $options{charset};
$req->body($p->to_string);
return $tx;
}

Expand Down
15 changes: 15 additions & 0 deletions t/mojo/transactor.t
Expand Up @@ -436,6 +436,8 @@ is $tx->req->headers->proxy_authorization, 'Basic c3JpOnNlY3IzdA==',
'right "Proxy-Authorization" header';
is $tx->req->headers->host, 'mojolicio.us', 'right "Host" header';
is $t->proxy_connect($tx), undef, 'already a CONNECT request';
$tx->req->method('Connect');
is $t->proxy_connect($tx), undef, 'already a CONNECT request';

# Simple 302 redirect
$tx = $t->tx(
Expand All @@ -453,6 +455,19 @@ is $tx->req->body, '', 'no content';
is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# 302 redirect (lowecase HEAD)
$tx = $t->tx(head => 'http://mojolicio.us/foo');
$tx->res->code(302);
$tx->res->headers->location('http://kraih.com/bar');
$tx = $t->redirect($tx);
is $tx->req->method, 'HEAD', 'right method';
is $tx->req->url->to_abs, 'http://kraih.com/bar', 'right URL';
is $tx->req->headers->accept, undef, 'no "Accept" value';
is $tx->req->headers->location, undef, 'no "Location" value';
is $tx->req->body, '', 'no content';
is $tx->res->code, undef, 'no status';
is $tx->res->headers->location, undef, 'no "Location" value';

# 302 redirect (dynamic)
$tx = $t->tx(POST => 'http://mojolicio.us/foo');
$tx->res->code(302);
Expand Down

0 comments on commit 1daaa72

Please sign in to comment.