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

jesse at bestpractical.com jesse at bestpractical.com
Mon Mar 21 07:08:56 EST 2005


Author: jesse
Date: Mon Mar 21 07:08:56 2005
New Revision: 2481

Modified:
   HTTP-Server-Simple/   (props changed)
   HTTP-Server-Simple/Changes
   HTTP-Server-Simple/lib/HTTP/Server/Simple.pm
   HTTP-Server-Simple/lib/HTTP/Server/Simple/CGI.pm
Log:
 r9491 at hualien:  jesse | 2005-03-21 20:08:41 +0800
 * code cleanup\n* ::CGI header handling fixes \n* ->headers calling convention changes


Modified: HTTP-Server-Simple/Changes
==============================================================================
--- HTTP-Server-Simple/Changes	(original)
+++ HTTP-Server-Simple/Changes	Mon Mar 21 07:08:56 2005
@@ -1,3 +1,11 @@
+0.03_04
+
+- Changed ->headers calling conventions. This may break backwards compat,
+  but is cleaner and safer.
+- Fixed bugs in ::CGI that broke http header handling
+- Refactored code to be more transparent
+
+
 0.03_03 Fri Mar 18 15:09:52 EST 2005
 - Finish fixes from http://rt.cpan.org/NoAuth/Bug.html?id=11409
 

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	Mon Mar 21 07:08:56 2005
@@ -192,8 +192,7 @@
 		my $headers = $self->parse_headers
 		    or do{$self->bad_request; next};
 
-		$self->setup( headers => $headers
-			    ) if $headers;
+		$self->headers( $headers) ;
 
 	    }
 
@@ -285,9 +284,11 @@
 
 Finally, you can define handlers to receive individual HTTP headers.
 This can be useful for very simple SOAP servers (to name a
-crack-fueled standard that defines its own special HTTP headers).  Eg,
-for a header called C<Content-Length>, you would define the method
-C<content_length()> in your sub-class.
+crack-fueled standard that defines its own special HTTP headers). 
+
+To do so, you'll want to define the C<header()> method in your subclass.
+That method will be handed a (key,value) pair of the header name and the value.
+
 
 =cut
 
@@ -299,14 +300,6 @@
     while ( my ($header, $value) = splice @$headers, 0, 2 ) {
 	if ( $can_header ) {
 	    $self->header($header => $value)
-	} else {
-	    (my $method = lc($header)) =~ s{-}{_}g;
-
-	    # FIXME - security - this is probably very dangerous
-	    # and probably OTT
-	    $self->$method($value)
-		if !defined &$method  # stop really dumb stuff
-		    and $self->can($method);
 	}
     }
 }
@@ -344,6 +337,7 @@
 
 Parse the HTTP request line.
 
+Returns three values, the request method, request URI and the protocol
 Sub-classed versions of this should return three values - request
 method, request URI and proto
 
@@ -354,12 +348,18 @@
     defined($_ = <STDIN>)
 	or return undef;
     chomp;
-    m/^(\w+)\s+(\S+)(?:\s+(\S+))?\r?$/
+
+    m/^(\w+)\s+(\S+)(?:\s+(\S+))?\r?$/;
+    my $method = $1;
+    my $uri = $2;
+    my $protocol = $3;
+
+    return($method, $uri, $protocol);
 }
 
 =head2 parse_headers
 
-Parse extra RFC822-style headers with the request.
+Parse incoming HTTP headers from STDIN.
 
 Remember, this is a B<simple> HTTP server, so nothing intelligent is
 done with them C<:-)>.
@@ -381,7 +381,7 @@
         }
         last if (/^$/);
     }
-    \@headers;
+    return(\@headers);
 }
 
 
@@ -400,9 +400,16 @@
     setsockopt( HTTPDaemon, SOL_SOCKET, SO_REUSEADDR, pack( "l", 1 ) )
       or warn "setsockopt: $!";
     bind( HTTPDaemon,
-	  sockaddr_in( $self->port(), ( $self->host ? inet_aton($self->host)
-					: INADDR_ANY ) ) )
-	or die "bind: $!";
+        sockaddr_in(
+            $self->port(),
+            (
+                $self->host
+                ? inet_aton( $self->host )
+                : INADDR_ANY
+            )
+        )
+      )
+      or die "bind: $!";
     listen( HTTPDaemon, SOMAXCONN ) or die "listen: $!";
 
 }

Modified: HTTP-Server-Simple/lib/HTTP/Server/Simple/CGI.pm
==============================================================================
--- HTTP-Server-Simple/lib/HTTP/Server/Simple/CGI.pm	(original)
+++ HTTP-Server-Simple/lib/HTTP/Server/Simple/CGI.pm	Mon Mar 21 07:08:56 2005
@@ -45,7 +45,6 @@
 
     $ENV{SERVER_URL} ||=
 	("http://".$ENV{SERVER_NAME}.":".$ENV{SERVER_PORT}."/");
-
     CGI::initialize_globals();
 }
 
@@ -84,7 +83,7 @@
 
 =head2  headers
 
-This method sets up the process environment in icky-CGI style based on
+This method sets up the process environment in CGI style based on
 the HTTP input headers.
 
 =cut
@@ -93,7 +92,8 @@
     my $self = shift;
     my $headers = shift;
 
-    while ( my ($tag, $value) = splice @_, 0, 2 ) {
+
+    while ( my ($tag, $value) = splice @$headers, 0, 2 ) {
 	$tag = uc($tag);
 	$tag =~ s/^COOKIES$/COOKIE/;
 	$tag =~ s/-/_/g;


More information about the Rt-commit mailing list