Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
there is no need to modify the handshake
  • Loading branch information
kraih committed Jan 10, 2016
1 parent 78d2ecd commit 0e3af25
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
22 changes: 3 additions & 19 deletions lib/Mojo/Transaction.pm
Expand Up @@ -10,22 +10,7 @@ has [
has req => sub { Mojo::Message::Request->new };
has res => sub { Mojo::Message::Response->new };

sub client_close {
my ($self, $close) = @_;

# Premature connection close
my $res = $self->res->finish;
if ($close && !$res->code && !$res->error) {
$res->error({message => 'Premature connection close'});
}

# 4xx/5xx
elsif ($res->is_status_class(400) || $res->is_status_class(500)) {
$res->error({message => $res->message, code => $res->code});
}

$self->server_close;
}
sub client_close { shift->server_close }

sub client_read { croak 'Method "client_read" not implemented by subclass' }
sub client_write { croak 'Method "client_write" not implemented by subclass' }
Expand Down Expand Up @@ -182,10 +167,9 @@ implements the following new ones.
=head2 client_close
$tx->client_close;
$tx->client_close(1);
Transaction closed client-side, no actual connection close is assumed by
default, used to implement user agents such as L<Mojo::UserAgent>.
Transaction closed client-side, used to implement user agents such as
L<Mojo::UserAgent>.
=head2 client_read
Expand Down
25 changes: 25 additions & 0 deletions lib/Mojo/Transaction/HTTP.pm
Expand Up @@ -3,6 +3,23 @@ use Mojo::Base 'Mojo::Transaction';

has [qw(next previous)];

sub client_close {
my ($self, $close) = @_;

# Premature connection close
my $res = $self->res->finish;
if ($close && !$res->code && !$res->error) {
$res->error({message => 'Premature connection close'});
}

# 4xx/5xx
elsif ($res->is_status_class(400) || $res->is_status_class(500)) {
$res->error({message => $res->message, code => $res->code});
}

$self->server_close;
}

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

Expand Down Expand Up @@ -252,6 +269,14 @@ L<Mojo::Transaction::HTTP> object.
L<Mojo::Transaction::HTTP> inherits all methods from L<Mojo::Transaction> and
implements the following new ones.
=head2 client_close
$tx->client_close;
$tx->client_close(1);
Transaction closed client-side, no actual connection close is assumed by
default, used to implement user agents such as L<Mojo::UserAgent>.
=head2 client_read
$tx->client_read($bytes);
Expand Down

0 comments on commit 0e3af25

Please sign in to comment.