Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
url->query is easier to type than query_params
  • Loading branch information
kraih committed Feb 27, 2015
1 parent ed31981 commit 9e4f1aa
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 59 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

6.01 2015-02-27
- Deprecated Mojo::Messages::Request::query_params.

6.0 2015-02-26
- Code name "Clinking Beer Mugs", this is a major release.
Expand Down
27 changes: 12 additions & 15 deletions lib/Mojo/Message/Request.pm
Expand Up @@ -2,7 +2,7 @@ package Mojo::Message::Request;
use Mojo::Base 'Mojo::Message';

use Mojo::Cookie::Request;
use Mojo::Util qw(b64_encode b64_decode);
use Mojo::Util qw(b64_encode b64_decode deprecated);
use Mojo::URL;

has env => sub { {} };
Expand Down Expand Up @@ -133,7 +133,7 @@ sub param { shift->params->param(@_) }
sub params {
my $self = shift;
return $self->{params}
||= $self->body_params->clone->append($self->query_params);
||= $self->body_params->clone->append($self->url->query);
}

sub parse {
Expand Down Expand Up @@ -182,7 +182,11 @@ sub proxy {
return $self;
}

sub query_params { shift->url->query }
# DEPRECATED in Clinking Beer Mugs!
sub query_params {
deprecated 'Mojo::Message::Request::query_params is DEPRECATED';
shift->url->query;
}

sub _parse_basic_auth {
return undef unless my $header = shift;
Expand Down Expand Up @@ -323,9 +327,11 @@ HTTP request method, defaults to C<GET>.
HTTP request URL, defaults to a L<Mojo::URL> object.
# Get request information
say $req->url->to_abs->userinfo;
say $req->url->to_abs->host;
say $req->url->to_abs->path;
my $info = $req->url->to_abs->userinfo;
my $host = $req->url->to_abs->host;
my $path = $req->url->to_abs->path;
my $query = $req->url->query;
my $hash = $req->url->query->to_hash;
=head2 reverse_proxy
Expand Down Expand Up @@ -449,15 +455,6 @@ Proxy URL for request.
# Disable proxy
$req->proxy(0);
=head2 query_params
my $params = $req->query_params;
All C<GET> parameters, usually a L<Mojo::Parameters> object.
# Turn GET parameters to hash and extract value
say $req->query_params->to_hash->{foo};
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
Expand Down
86 changes: 43 additions & 43 deletions t/mojo/request.t
Expand Up @@ -631,12 +631,12 @@ $req->parse("abcdefghi\x0d\x0a");
$req->parse("0\x0d\x0a");
$req->parse("X-Trailer1: test\x0d\x0a");
$req->parse("X-Trailer2: 123\x0d\x0a\x0d\x0a");
ok $req->is_finished, 'request is finished';
is $req->method, 'POST', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo=13&bar=23#23', 'right URL';
is $req->query_params, 'foo=13&bar=23', 'right parameters';
is $req->headers->content_type, 'text/plain', 'right "Content-Type" value';
ok $req->is_finished, 'request is finished';
is $req->method, 'POST', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo=13&bar=23#23', 'right URL';
is $req->url->query, 'foo=13&bar=23', 'right parameters';
is $req->headers->content_type, 'text/plain', 'right "Content-Type" value';
is $req->headers->header('X-Trailer1'), 'test', 'right "X-Trailer1" value';
is $req->headers->header('X-Trailer2'), '123', 'right "X-Trailer2" value';
is $req->headers->content_length, 13, 'right "Content-Length" value';
Expand All @@ -654,11 +654,11 @@ $req->parse("abcd\x0d\x0a");
$req->parse("9\x0d\x0a");
$req->parse("abcdefghi\x0d\x0a");
$req->parse("0\x0d\x0aX-Trailer: 777\x0d\x0a\x0d\x0aLEFTOVER");
ok $req->is_finished, 'request is finished';
is $req->method, 'POST', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo=13&bar=23#23', 'right URL';
is $req->query_params, 'foo=13&bar=23', 'right parameters';
ok $req->is_finished, 'request is finished';
is $req->method, 'POST', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo=13&bar=23#23', 'right URL';
is $req->url->query, 'foo=13&bar=23', 'right parameters';
ok !defined $req->headers->transfer_encoding, 'no "Transfer-Encoding" value';
is $req->headers->content_type, 'text/plain', 'right "Content-Type" value';
is $req->headers->header('X-Trailer'), '777', 'right "X-Trailer" value';
Expand All @@ -678,12 +678,12 @@ $req->parse("9\x0d\x0a");
$req->parse("abcdefghi\x0d\x0a");
$req->parse(
"0\x0d\x0aX-Trailer1: test\x0d\x0aX-Trailer2: 123\x0d\x0a\x0d\x0a");
ok $req->is_finished, 'request is finished';
is $req->method, 'POST', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo=13&bar=23#23', 'right URL';
is $req->query_params, 'foo=13&bar=23', 'right parameters';
is $req->headers->content_type, 'text/plain', 'right "Content-Type" value';
ok $req->is_finished, 'request is finished';
is $req->method, 'POST', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo=13&bar=23#23', 'right URL';
is $req->url->query, 'foo=13&bar=23', 'right parameters';
is $req->headers->content_type, 'text/plain', 'right "Content-Type" value';
is $req->headers->header('X-Trailer1'), 'test', 'right "X-Trailer1" value';
is $req->headers->header('X-Trailer2'), '123', 'right "X-Trailer2" value';
is $req->headers->content_length, 13, 'right "Content-Length" value';
Expand All @@ -701,12 +701,12 @@ $req->parse("9\x0d\x0a");
$req->parse("abcdefghi\x0d\x0a");
$req->parse(
"0\x0d\x0aX-Trailer1: test\x0d\x0aX-Trailer2: 123\x0d\x0a\x0d\x0a");
ok $req->is_finished, 'request is finished';
is $req->method, 'POST', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo=13&bar=23#23', 'right URL';
is $req->query_params, 'foo=13&bar=23', 'right parameters';
is $req->headers->content_type, 'text/plain', 'right "Content-Type" value';
ok $req->is_finished, 'request is finished';
is $req->method, 'POST', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo=13&bar=23#23', 'right URL';
is $req->url->query, 'foo=13&bar=23', 'right parameters';
is $req->headers->content_type, 'text/plain', 'right "Content-Type" value';
is $req->headers->header('X-Trailer1'), 'test', 'right "X-Trailer1" value';
is $req->headers->header('X-Trailer2'), '123', 'right "X-Trailer2" value';
is $req->headers->content_length, 13, 'right "Content-Length" value';
Expand Down Expand Up @@ -741,10 +741,10 @@ $req->parse("\x0d\x0a------------0xKhTmLbOuNdArY--");
is $req->content->progress, 416, 'right progress';
ok $req->is_finished, 'request is finished';
ok $req->content->is_multipart, 'multipart content';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
is $req->query_params, 'foo13', 'right parameters';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
is $req->url->query, 'foo13', 'right parameters';
is $req->headers->content_type,
'multipart/form-data; boundary=----------0xKhTmLbOuNdArY',
'right "Content-Type" value';
Expand Down Expand Up @@ -803,10 +803,10 @@ $req->parse("print \"Hello World :)\\n\"\n");
$req->parse("\x0d\x0a------------0xKhTmLbOuNdArY--");
ok $req->is_finished, 'request is finished';
ok $req->content->is_multipart, 'multipart content';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
is $req->query_params, 'foo13', 'right parameters';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
is $req->url->query, 'foo13', 'right parameters';
is $req->headers->content_type,
'multipart/form-data; boundary=----------0xKhTmLbOuNdArY',
'right "Content-Type" value';
Expand Down Expand Up @@ -879,10 +879,10 @@ is $stream, "#!/usr/bin/perl\n\nuse strict;\nuse war", 'right content';
$req->parse("\x0d\x0a------------0xKhTmLbOuNdArY--");
ok $req->is_finished, 'request is finished';
ok $req->content->is_multipart, 'multipart content';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
is $req->query_params, 'foo13', 'right parameters';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
is $req->url->query, 'foo13', 'right parameters';
is $req->headers->content_type,
'multipart/form-data; boundary=----------0xKhTmLbOuNdArY',
'right "Content-Type" value';
Expand Down Expand Up @@ -923,10 +923,10 @@ $req->parse("print \"Hello World :)\\n\"\n");
$req->parse("\x0d\x0a------------0xKhTmLbOuNdArY--");
ok $req->is_finished, 'request is finished';
ok !$req->content->is_multipart, 'no multipart content';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
is $req->query_params, 'foo13', 'right parameters';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
is $req->url->query, 'foo13', 'right parameters';
is $req->headers->content_type,
'multipart/form-data; boundary=----------0xKhTmLbOuNdArY',
'right "Content-Type" value';
Expand Down Expand Up @@ -957,10 +957,10 @@ $req->parse("print \"Hello World :)\\n\"\n");
$req->parse("\x0d\x0a------------0xKhTmLbOuNdArY--");
ok $req->is_finished, 'request is finished';
ok $req->content->is_multipart, 'no multipart content';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
is $req->query_params, 'foo13', 'right parameters';
is $req->method, 'GET', 'right method';
is $req->version, '1.1', 'right version';
is $req->url, '/foo/bar/baz.html?foo13#23', 'right URL';
is $req->url->query, 'foo13', 'right parameters';
is $req->headers->content_type,
'multipart/form-data; boundary=----------0xKhTmLbOuNdArY',
'right "Content-Type" value';
Expand Down
5 changes: 4 additions & 1 deletion t/pod_coverage.t
Expand Up @@ -7,4 +7,7 @@ plan skip_all => 'set TEST_POD to enable this test (developer only!)'
plan skip_all => 'Test::Pod::Coverage 1.04+ required for this test!'
unless eval 'use Test::Pod::Coverage 1.04; 1';

all_pod_coverage_ok();
# DEPRECATED in Clinking Beer Mugs!
my @beer = ('query_params');

all_pod_coverage_ok({also_private => [@beer]});

0 comments on commit 9e4f1aa

Please sign in to comment.