[Rt-commit] r3941 - in HTTP-Server-Simple: . lib/HTTP/Server

jesse at bestpractical.com jesse at bestpractical.com
Fri Oct 7 01:14:16 EDT 2005


Author: jesse
Date: Fri Oct  7 01:14:16 2005
New Revision: 3941

Modified:
   HTTP-Server-Simple/   (props changed)
   HTTP-Server-Simple/Changes
   HTTP-Server-Simple/META.yml
   HTTP-Server-Simple/SIGNATURE
   HTTP-Server-Simple/lib/HTTP/Server/Simple.pm
Log:
 r17223 at hualien:  jesse | 2005-10-06 21:12:57 -0400
 * 0.15


Modified: HTTP-Server-Simple/Changes
==============================================================================
--- HTTP-Server-Simple/Changes	(original)
+++ HTTP-Server-Simple/Changes	Fri Oct  7 01:14:16 2005
@@ -1,3 +1,7 @@
+0.15 Thu Oct  6 21:11:02 EDT 2005
+
+  Precompute the local host's hostname and IP to save on DNS lookups at runtime 
+
 0.14 Thu Oct  6 20:48:49 EDT 2005
 
   Split out HTTP::Server::Simple::CGI::Environment to support non-CGI.pm CGIs

Modified: HTTP-Server-Simple/META.yml
==============================================================================
--- HTTP-Server-Simple/META.yml	(original)
+++ HTTP-Server-Simple/META.yml	Fri Oct  7 01:14:16 2005
@@ -1,5 +1,5 @@
 name: HTTP-Server-Simple
-version: 0.14
+version: 0.15
 license: perl
 distribution_type: module
 requires:

Modified: HTTP-Server-Simple/SIGNATURE
==============================================================================
--- HTTP-Server-Simple/SIGNATURE	(original)
+++ HTTP-Server-Simple/SIGNATURE	Fri Oct  7 01:14:16 2005
@@ -14,9 +14,9 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-SHA1 0c488ab4994eac2508accc469185829250c0cfcf Changes
+SHA1 325aa2f58308731eaeb6e68943ab09ecda0f547c Changes
 SHA1 0ac508c50476dcc2bf8fe3094cb341425291e1ee MANIFEST
-SHA1 c2533ce46b89fa0eb1e0c864548265ade18b241e META.yml
+SHA1 ea11c9c2f69fb085db70d70ae22711eec5fdf757 META.yml
 SHA1 490f3fd115e09cb05b725580e5ed5cdd58241049 Makefile.PL
 SHA1 ed0c107672daac3bc9e266876666e1059dbe44b7 README
 SHA1 4ea1e9072ca87399184a46233df52a21e285604d ex/sample_server
@@ -28,7 +28,7 @@
 SHA1 e448c6dc5351ef425e3f8bdbeb642409120bc3ca inc/Module/Install/Metadata.pm
 SHA1 134de6ff2f762873b6a1af950dd53f8e0a801d73 inc/Module/Install/Win32.pm
 SHA1 1ec06df292af7f652d33db6129e9e4c7cc8b5095 inc/Module/Install/WriteAll.pm
-SHA1 3d04ee229d832f7ac61f9e8d531851166450a8b2 lib/HTTP/Server/Simple.pm
+SHA1 9434a1f10b29486cf7ea3628eecb07aff01c2581 lib/HTTP/Server/Simple.pm
 SHA1 2d7348b166f654a460ddae4cb4183f4a544c85fc lib/HTTP/Server/Simple/CGI.pm
 SHA1 b2c2d007a7f50058c874e633d15fb621b2bfc394 lib/HTTP/Server/Simple/CGI/Environment.pm
 SHA1 db064af54cab345a71daec576e32e64b8fb1033d t/00smoke.t
@@ -39,7 +39,7 @@
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.1 (GNU/Linux)
 
-iD8DBQFDRcavEi9d9xCOQEYRAnt5AJwLOBRZx/eCUOnh9Bzr1eSF75CESwCgmCJ6
-CXwhh2oHIUdpWPmZYcqfz2w=
-=Cpw+
+iD8DBQFDRctZEi9d9xCOQEYRAl6zAJ0Y7M0TDCmG45QXXcVFqtm/Vp98EQCeMQqg
+K69+8uz38xf+wkYTLVNGg94=
+=gqiT
 -----END PGP SIGNATURE-----

Modified: HTTP-Server-Simple/lib/HTTP/Server/Simple.pm
==============================================================================
--- HTTP-Server-Simple/lib/HTTP/Server/Simple.pm	(original)
+++ HTTP-Server-Simple/lib/HTTP/Server/Simple.pm	Fri Oct  7 01:14:16 2005
@@ -5,7 +5,7 @@
 use Socket;
 use Carp;
 
-our $VERSION = '0.14';
+our $VERSION = '0.15';
 
 =head1 NAME
 
@@ -71,6 +71,7 @@
 until you call C<-E<gt>run()>.
 
 =cut
+
 sub new {
     my ( $proto, $port ) = @_;
     my $class = ref($proto) || $proto;
@@ -83,9 +84,35 @@
     my $self = {};
     bless( $self, $class );
     $self->port( $port || '8080' );
+
+
+
     return $self;
 }
 
+
+=head2 lookup_localhost
+
+Looks up the local host's hostname and IP address.
+
+Stuffs them into
+
+$self->{'localname'} and $self->{'localaddr'}
+
+=cut
+
+sub lookup_localhost {
+    my $self = shift;
+
+    my $local_sockaddr = getsockname( $self->stdio_handle );
+    my ( undef, $localiaddr ) = sockaddr_in($local_sockaddr);
+    $self->host( gethostbyaddr( $localiaddr, AF_INET ) || "localhost");
+    $self->{'local_addr'} = inet_ntoa($localiaddr) || "127.0.0.1";
+}
+
+
+
+
 =head2 port [NUMBER]
 
 Takes an optional port number for this server to listen on.
@@ -218,8 +245,10 @@
                  # finish sending will cause the server to exit
             while ( accept( my $remote, HTTPDaemon ) ) {
                 $self->stdio_handle($remote);
+                $self->lookup_localhost() unless ($self->host);
                 $self->accept_hook if $self->can("accept_hook");
 
+
                 *STDIN  = $self->stdin_handle();
                 *STDOUT = $self->stdout_handle();
                 select STDOUT;   # required for HTTP::Server::Simple::Recorder
@@ -249,11 +278,6 @@
         my ( undef, $iaddr ) = sockaddr_in($remote_sockaddr);
         my $peeraddr = inet_ntoa($iaddr) || "127.0.0.1";
 
-        my $local_sockaddr = getsockname( $self->stdio_handle );
-        my ( undef, $localiaddr ) = sockaddr_in($local_sockaddr);
-        my $localname = gethostbyaddr( $localiaddr, AF_INET ) || "localhost";
-        my $localaddr = inet_ntoa($localiaddr) || "127.0.0.1";
-
         my ( $method, $request_uri, $proto ) = $self->parse_request
             or do { $self->bad_request; return };
 
@@ -273,7 +297,7 @@
             query_string => ( $query_string || '' ),
             request_uri  => $request_uri,
             path         => $file,
-            localname    => $localname,
+            localname    => $self->host,
             localport    => $self->port,
             peername     => $peeraddr,
             peeraddr     => $peeraddr,
@@ -295,6 +319,10 @@
         }
 }
 
+
+
+
+
 =head2 stdio_handle [FILEHANDLE]
 
 When called with an argument, sets the socket to the server to that arg.


More information about the Rt-commit mailing list