Skip to content

Commit

Permalink
Improved form content generator for GET and HEAD requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jberger committed Apr 22, 2013
1 parent 1daaa72 commit bc89f53
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -11,6 +11,7 @@
- Fixed a few small clone bugs.
- Fixed a few small redirect and proxy connect bugs in
Mojo::UserAgent::Transactor.
- Improved form content generator for GET and HEAD requests (jberger)

3.95 2013-04-12
- Added finished_ok method to Test::Mojo.
Expand Down
7 changes: 5 additions & 2 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -189,7 +189,9 @@ sub _form {
$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);
my $method = uc $req->method;
if ($method eq 'GET' || $method eq 'HEAD') { $req->url->query->merge($p) }
else { $req->body($p->to_string) }
return $tx;
}

Expand Down Expand Up @@ -405,7 +407,8 @@ requests, with support for content generators.
While the "multipart/form-data" content type will be automatically used
instead of "application/x-www-form-urlencoded" when necessary, you can also
enforce it by setting the header manually.
enforce it by setting the header manually. GET and HEAD transactions merge
form paramters into the url query parameters.
=head2 upgrade
Expand Down
10 changes: 9 additions & 1 deletion t/mojo/transactor.t
Expand Up @@ -100,14 +100,22 @@ is $tx->req->headers->content_type, 'application/something',
'right "Content-Type" value';
is_deeply $tx->req->json, [1, 2], 'right content';

# Simple form
# Simple form (POST)
$tx = $t->tx(POST => 'http://kraih.com/foo' => form => {test => 123});
is $tx->req->url->to_abs, 'http://kraih.com/foo', 'right URL';
is $tx->req->method, 'POST', 'right method';
is $tx->req->headers->content_type, 'application/x-www-form-urlencoded',
'right "Content-Type" value';
is $tx->req->body, 'test=123', 'right content';

# Simple form (GET)
$tx = $t->tx(GET => 'http://kraih.com/foo' => form => {test => 123});
is $tx->req->url->to_abs, 'http://kraih.com/foo?test=123', 'right URL';
is $tx->req->method, 'GET', 'right method';
is $tx->req->headers->content_type, 'application/x-www-form-urlencoded',
'right "Content-Type" value';
is $tx->req->body, '', 'right content';

# Simple form with multiple values
$tx
= $t->tx(POST => 'http://kraih.com/foo' => form => {a => [1, 2, 3], b => 4});
Expand Down

0 comments on commit bc89f53

Please sign in to comment.