Skip to content

Commit

Permalink
only WebSocket handshakes have redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 31, 2013
1 parent b25c38e commit 3ca79dc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,6 +1,6 @@

4.23 2013-07-31
- Added redirects method to Mojo::Transaction.
- Added redirects method to Mojo::Transaction::HTTP.

4.22 2013-07-30
- Improved Mojo::Server to use FindBin more defensively.
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/Headers.pm
Expand Up @@ -454,6 +454,7 @@ Shortcut for the C<Location> header.
Return a list of all currently defined headers.
# Names of all headers
say for @{$headers->names};
=head2 origin
Expand Down
28 changes: 1 addition & 27 deletions lib/Mojo/Transaction.pm
Expand Up @@ -5,7 +5,7 @@ use Carp 'croak';
use Mojo::Message::Request;
use Mojo::Message::Response;

has [qw(kept_alive local_address local_port previous remote_port)];
has [qw(kept_alive local_address local_port remote_port)];
has req => sub { Mojo::Message::Request->new };
has res => sub { Mojo::Message::Response->new };

Expand Down Expand Up @@ -38,13 +38,6 @@ sub is_websocket {undef}

sub is_writing { (shift->{state} // 'write') eq 'write' }

sub redirects {
my $previous = shift;
my @redirects;
unshift @redirects, $previous while $previous = $previous->previous;
return \@redirects;
}

sub remote_address {
my $self = shift;

Expand Down Expand Up @@ -157,16 +150,6 @@ Local interface address.
Local interface port.
=head2 previous
my $previous = $tx->previous;
$tx = $tx->previous(Mojo::Transaction->new);
Previous transaction that triggered this followup transaction.
# Path of previous request
say $tx->previous->req->url->path;
=head2 remote_port
my $port = $tx->remote_port;
Expand Down Expand Up @@ -251,15 +234,6 @@ Check if transaction is writing.
Resume transaction.
=head2 redirects
my $redirects = $tx->redirects;
Return a list of all previous transactions that preceded this followup
transaction.
say $_->req->url for @{$tx->redirects};
=head2 remote_address
my $address = $tx->remote_address;
Expand Down
32 changes: 31 additions & 1 deletion lib/Mojo/Transaction/HTTP.pm
Expand Up @@ -3,6 +3,8 @@ use Mojo::Base 'Mojo::Transaction';

use Mojo::Transaction::WebSocket;

has 'previous';

sub client_read {
my ($self, $chunk) = @_;

Expand Down Expand Up @@ -40,6 +42,13 @@ sub keep_alive {
return !($req->version eq '1.0' || $res->version eq '1.0');
}

sub redirects {
my $previous = shift;
my @redirects;
unshift @redirects, $previous while $previous = $previous->previous;
return \@redirects;
}

sub server_read {
my ($self, $chunk) = @_;

Expand Down Expand Up @@ -247,7 +256,18 @@ object.
=head1 ATTRIBUTES
L<Mojo::Transaction::HTTP> inherits all attributes from L<Mojo::Transaction>.
L<Mojo::Transaction::HTTP> inherits all attributes from L<Mojo::Transaction>
and implements the following new ones.
=head2 previous
my $previous = $tx->previous;
$tx = $tx->previous(Mojo::Transaction->new);
Previous transaction that triggered this followup transaction.
# Path of previous request
say $tx->previous->req->url->path;
=head1 METHODS
Expand Down Expand Up @@ -278,6 +298,16 @@ Check transaction for C<HEAD> request and C<1xx>, C<204> or C<304> response.
Check if connection can be kept alive.
=head2 redirects
my $redirects = $tx->redirects;
Return a list of all previous transactions that preceded this followup
transaction.
# Paths of all previous requests
say $_->req->url->path for @{$tx->redirects};
=head2 server_read
$tx->server_read($bytes);
Expand Down

0 comments on commit 3ca79dc

Please sign in to comment.