Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #8 from kazeburo/master

Set REMOTE_PORT environment variable
  • Loading branch information...
commit d00111519ec14525fc395311abda618637f453f2 2 parents 6f4d272 + 3258442
Kazuho Oku authored September 10, 2012
1  lib/Starlet/Server.pm
@@ -106,6 +106,7 @@ sub accept_loop {
106 106
                     SERVER_NAME => $self->{host},
107 107
                     SCRIPT_NAME => '',
108 108
                     REMOTE_ADDR => $conn->peerhost,
  109
+                    REMOTE_PORT => $conn->peerport,
109 110
                     'psgi.version' => [ 1, 1 ],
110 111
                     'psgi.errors'  => *STDERR,
111 112
                     'psgi.url_scheme' => 'http',
41  t/06remote_port.t
... ...
@@ -0,0 +1,41 @@
  1
+use strict;
  2
+use warnings;
  3
+use Test::More;
  4
+use Test::TCP;
  5
+use LWP::UserAgent;
  6
+use IO::Socket::INET;
  7
+use Plack::Loader;
  8
+
  9
+test_tcp(
  10
+    client => sub {
  11
+        my $port = shift;
  12
+        sleep 1;
  13
+        my $sock = IO::Socket::INET->new(
  14
+            PeerAddr => "localhost:$port",
  15
+            Proto => 'tcp',
  16
+        );
  17
+        ok($sock);
  18
+        my $localport = $sock->sockport;
  19
+        my $req = "GET / HTTP/1.0\015\012\015\012";
  20
+        $sock->syswrite($req,length($req));
  21
+        $sock->sysread( my $buf, 1024);
  22
+        like( $buf, qr/HELLO $localport/);
  23
+    },
  24
+    server => sub {
  25
+        my $port = shift;
  26
+        my $loader = Plack::Loader->load(
  27
+            'Starlet',
  28
+            port => $port,
  29
+            max_workers => 5,
  30
+        );
  31
+        $loader->run(sub{
  32
+            my $env = shift;
  33
+            my @headers = ();
  34
+            my $remote_port = $env->{REMOTE_PORT};
  35
+            [200, ['Content-Type'=>'text/html'], ['HELLO '.$remote_port]];
  36
+        });
  37
+    },
  38
+);
  39
+
  40
+done_testing;
  41
+

0 notes on commit d001115

Please sign in to comment.
Something went wrong with that request. Please try again.