Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a super hack to store raw socket when a request begins and

stores that to psgix.io in $env.
  • Loading branch information...
commit 27af2d87408b77d1f29fcbfa6b83a7d4de58bbe3 1 parent 3189b17
@miyagawa authored
Showing with 14 additions and 0 deletions.
  1. +14 −0 lib/Plack/Handler/AnyEvent/HTTPD.pm
View
14 lib/Plack/Handler/AnyEvent/HTTPD.pm
@@ -9,6 +9,8 @@ use Plack::Util;
use HTTP::Status;
use URI::Escape;
+my %_sockets;
+
sub new {
my($class, %args) = @_;
bless {%args}, $class;
@@ -23,6 +25,12 @@ sub register_service {
connection_class => 'Plack::Handler::AnyEvent::HTTPD::Connection',
request_timeout => $self->{request_timeout},
);
+
+ $httpd->reg_cb(client_disconnected => sub {
+ my($httpd, $host, $port) = @_;
+ delete $_sockets{join(":", $host, $port)};
+ });
+
$httpd->reg_cb(
'' => sub {
my($httpd, $req) = @_;
@@ -49,6 +57,7 @@ sub register_service {
open my $input, "<", \(defined $req->content ? $req->content : '');
$input;
},
+ 'psgix.io' => $_sockets{join(":", $req->client_host, $req->client_port)},
};
my $hdr = $req->headers;
@@ -78,6 +87,7 @@ sub register_service {
}
$req->respond([ @res, $content ]);
+ delete $_sockets{join(":", $req->client_host, $req->client_port)};
return;
} else {
@@ -124,6 +134,10 @@ use parent qw(AnyEvent::HTTPD::HTTPConnection);
sub handle_request {
my($self, $method, $uri, $hdr, $cont) = @_;
+ Scalar::Util::weaken(
+ $_sockets{join(":", $self->{host}, $self->{port})} = $self->{hdl}->{fh}
+ );
+
$self->{keep_alive} = ($hdr->{connection} =~ /keep-alive/io);
$self->event(request => $method, $uri, $hdr, $cont);
}
Please sign in to comment.
Something went wrong with that request. Please try again.