Skip to content

Instantly share code, notes, and snippets.

/close.diff Secret

Created January 9, 2016 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0eba6868f2c64af665d2 to your computer and use it in GitHub Desktop.
Save anonymous/0eba6868f2c64af665d2 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Transaction.pm b/lib/Mojo/Transaction.pm
index 7bafadd..67f255a 100644
--- a/lib/Mojo/Transaction.pm
+++ b/lib/Mojo/Transaction.pm
@@ -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 connection {
my $self = shift;
diff --git a/lib/Mojo/Transaction/HTTP.pm b/lib/Mojo/Transaction/HTTP.pm
index b86fbf1..c77db09 100644
--- a/lib/Mojo/Transaction/HTTP.pm
+++ b/lib/Mojo/Transaction/HTTP.pm
@@ -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 is_empty { !!(uc $_[0]->req->method eq 'HEAD' || $_[0]->res->is_empty) }
sub keep_alive {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment