Skip to content

Commit

Permalink
added x_requested_with method to Mojo::Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 30, 2012
1 parent a628a33 commit 11819d7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Changes
Expand Up @@ -5,8 +5,8 @@ This file documents the revision history for Perl extension Mojolicious.
- Added EXPERIMENTAL drain event to Mojo::Transaction::WebSocket.
- Added EXPERIMENTAL support for RSV1-3 flags to
Mojo::Transaction::WebSocket.
- Added x_forwarded_host and x_forwarded_https methods to
Mojo::Headers.
- Added x_forwarded_host, x_forwarded_https and x_requested_with
methods to Mojo::Headers.
- Removed experimental status from JSON Pointer support.
- Added pdf MIME type. (bfaist)
- Improved documentation.
Expand Down
9 changes: 8 additions & 1 deletion lib/Mojo/Headers.pm
Expand Up @@ -15,7 +15,7 @@ my @HEADERS = (
qw/Sec-WebSocket-Key Sec-WebSocket-Origin Sec-WebSocket-Protocol/,
qw/Sec-WebSocket-Version Server Set-Cookie Status Trailer/,
qw/Transfer-Encoding Upgrade User-Agent WWW-Authenticate X-Forwarded-For/,
qw/X-Forwarded-Host X-Forwarded-HTTPS/
qw/X-Forwarded-Host X-Forwarded-HTTPS X-Requested-With/
);
{
no strict 'refs';
Expand Down Expand Up @@ -609,6 +609,13 @@ Shortcut for the C<X-Forwarded-Host> header.
Shortcut for the C<X-Forwarded-HTTPS> header.
=head2 C<x_requested_with>
my $x_requested_with = $headers->x_requested_with;
$headers = $headers->x_requested_with('XMLHttpRequest');
Shortcut for the C<X-Requested-With> header.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
Expand Down
4 changes: 1 addition & 3 deletions lib/Mojo/Message/Request.pm
Expand Up @@ -91,9 +91,7 @@ sub is_secure {
return ($url->scheme || $url->base->scheme || '') eq 'https';
}

sub is_xhr {
(shift->headers->header('X-Requested-With') || '') =~ /XMLHttpRequest/i;
}
sub is_xhr { (shift->headers->x_requested_with || '') =~ /XMLHttpRequest/i }

sub param {
my $self = shift;
Expand Down
3 changes: 2 additions & 1 deletion t/mojo/headers.t
@@ -1,7 +1,7 @@
use Mojo::Base -strict;

# "Remember, you can always find East by staring directly at the sun."
use Test::More tests => 91;
use Test::More tests => 92;

# "So, have a merry Christmas, a happy Hanukkah, a kwaazy Kwanza,
# a tip-top Tet, and a solemn, dignified, Ramadan.
Expand Down Expand Up @@ -96,6 +96,7 @@ is $headers->x_forwarded_for('foo')->x_forwarded_for, 'foo', 'right value';
is $headers->x_forwarded_host('foo')->x_forwarded_host, 'foo', 'right value';
is $headers->x_forwarded_https('foo')->x_forwarded_https, 'foo',
'right value';
is $headers->x_requested_with('foo')->x_requested_with, 'foo', 'right value';

# Clone
$headers = Mojo::Headers->new;
Expand Down

0 comments on commit 11819d7

Please sign in to comment.