r59492 - in /branches/upstream/libhttp-parser-perl/current: Changes META.yml Makefile.PL Parser.pm README

ansgar-guest at users.alioth.debian.org ansgar-guest at users.alioth.debian.org
Fri Jun 18 06:38:16 UTC 2010


Author: ansgar-guest
Date: Fri Jun 18 06:37:42 2010
New Revision: 59492

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=59492
Log:
[svn-upgrade] new version libhttp-parser-perl (0.05)

Modified:
    branches/upstream/libhttp-parser-perl/current/Changes
    branches/upstream/libhttp-parser-perl/current/META.yml
    branches/upstream/libhttp-parser-perl/current/Makefile.PL
    branches/upstream/libhttp-parser-perl/current/Parser.pm
    branches/upstream/libhttp-parser-perl/current/README

Modified: branches/upstream/libhttp-parser-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-perl/current/Changes?rev=59492&op=diff
==============================================================================
--- branches/upstream/libhttp-parser-perl/current/Changes (original)
+++ branches/upstream/libhttp-parser-perl/current/Changes Fri Jun 18 06:37:42 2010
@@ -1,4 +1,12 @@
 Revision history for Perl extension HTTP::Parser.
+
+0.05  2009-11-13
+  - two fixes by David Cannings <david at edeca.net>
+  - when parsing responses with no Content-Length header, return a different
+     code to the caller so it can decide whether to keep adding data or not
+     (a slightly more elegant fix to rt.cpan.org #34021)
+  - parse the HTTP response message correctly, it can contain multiple words
+     (rt.cpan.org #34019)
 
 0.04  2007-11-10
   - when parsing chunks, only remove current chunk from data buffer; don't

Modified: branches/upstream/libhttp-parser-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-perl/current/META.yml?rev=59492&op=diff
==============================================================================
--- branches/upstream/libhttp-parser-perl/current/META.yml (original)
+++ branches/upstream/libhttp-parser-perl/current/META.yml Fri Jun 18 06:37:42 2010
@@ -1,13 +1,25 @@
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
-name:         HTTP-Parser
-version:      0.04
-version_from: Parser.pm
-installdirs:  site
+--- #YAML:1.0
+name:               HTTP-Parser
+version:            0.05
+abstract:           parse HTTP/1.1 request into HTTP::Request/Response object
+author:
+    - David. B. Robins <dbrobins at davidrobins.net>
+license:            perl
+distribution_type:  module
+configure_requires:
+    ExtUtils::MakeMaker:  0
+build_requires:
+    ExtUtils::MakeMaker:  0
 requires:
-    HTTP::Request:                 0
-    HTTP::Response:                0
-    URI:                           0
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.30
+    HTTP::Request:   0
+    HTTP::Response:  0
+    Test::More:      0
+    URI:             0
+no_index:
+    directory:
+        - t
+        - inc
+generated_by:       ExtUtils::MakeMaker version 6.54
+meta-spec:
+    url:      http://module-build.sourceforge.net/META-spec-v1.4.html
+    version:  1.4

Modified: branches/upstream/libhttp-parser-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-perl/current/Makefile.PL?rev=59492&op=diff
==============================================================================
--- branches/upstream/libhttp-parser-perl/current/Makefile.PL (original)
+++ branches/upstream/libhttp-parser-perl/current/Makefile.PL Fri Jun 18 06:37:42 2010
@@ -9,7 +9,9 @@
                          'URI'            => 0,
                          'HTTP::Request'  => 0,
                          'HTTP::Response' => 0,
+                         'Test::More'     => 0,
                        },
+    'LICENSE'   => 'perl',
     ($] >= 5.005 ?    ## Add these new keywords supported since 5.005
       (ABSTRACT_FROM => 'Parser.pm', # retrieve abstract from module
        AUTHOR     => 'David. B. Robins <dbrobins at davidrobins.net>') : ()),

Modified: branches/upstream/libhttp-parser-perl/current/Parser.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-perl/current/Parser.pm?rev=59492&op=diff
==============================================================================
--- branches/upstream/libhttp-parser-perl/current/Parser.pm (original)
+++ branches/upstream/libhttp-parser-perl/current/Parser.pm Fri Jun 18 06:37:42 2010
@@ -12,6 +12,8 @@
 
  if(0 == $status) {
    print "request: ".$parser->request()->as_string();  # HTTP::Request
+ } elsif(-3 == $status) {
+   print "no content length header!\n";
  } elsif(-2 == $status) {
    print "need a line of data\n";
  } elsif(-1 == $status) {
@@ -33,7 +35,7 @@
 
 package HTTP::Parser;
 
-our $VERSION = '0.04';
+our $VERSION = '0.05';
 
 use HTTP::Request;
 use HTTP::Response;
@@ -98,6 +100,21 @@
 
 if waiting for a line (like 0 with a hint)
 
+=item -3
+
+if there was no content-length header, so we can't tell whether we are 
+waiting for more data or not.
+
+If you are reading from a TCP stream, you can keep adding data until 
+the connection closes gracefully (the HTTP RFC allows this).
+
+If you are reading from a file, you should keep adding until you have 
+all the data.  
+
+Once you have added all data, you may call C<object>.  if you are not 
+sure whether you have all the data, the HTTP::Response object might be 
+incomplete.
+
 =item count
 
 if waiting for that many bytes
@@ -231,7 +248,9 @@
     if ($request =~ /^HTTP\/(\d+)\.(\d+)/i) {
       die 'HTTP responses not allowed' unless $self->{response};
       ($major,$minor) = ($1,$2);
-      my (undef, $state, $msg) = split / /,$request;
+      $request =~ /^HTTP\/\d+\.\d+ (\d+) (.+)$/;
+      my $state = $1;
+      my $msg = $2;
       $obj = $self->{obj} = HTTP::Response->new($state, $msg);
 
     # perhaps a request?
@@ -277,6 +296,32 @@
     }
   }
 
+  # section 14.13 of the spec says an HTTP response "SHOULD" return a 
+  # content-length header unless there are reasons not to
+  # however, the same RFC does allow "end of connection" as a valid marker
+  # of the end of data and means the server does not need to set a content
+  # length header.  the only status codes that "MAY NOT" return data are
+  # 1xx, 204 and 304.
+  # therefore if there is no content length header, return -3 to the caller
+  # so they can decide whether to keep feeding data.  if using HTTP::Parser
+  # with data from tcp, you could assume that the end of a connection is
+  # the end of the response data
+  if($self->{response}) {
+    if (!defined $obj->header('content_length') &&
+     $self->object->code ne '204' &&
+     $self->object->code ne '304' &&
+     $self->object->code !~ /1\d\d/) {
+
+      # Assume headers are finished and we are moving into body mode
+      $self->{state} = 'body';
+      $self->{no_content_length} = 1;
+
+      # Parse any data that might be left
+      return $self->_parse_body() if length $self->data;
+      return -3;
+    }
+  }
+
   # else we have no content so return success
   return 0;
 }
@@ -290,6 +335,16 @@
 sub _parse_body {
   my $self = shift;
   my $length = $self->{obj}->header('content_length');
+
+  # if the server didn't include a content length header, inform the
+  # caller.  they may choose to ignore this response or wait for
+  # the end of connection (which is a valid reason to assume that
+  # the response is finished)
+  if($self->{no_content_length}) {
+    $self->{obj}->content($self->{data});
+    return -3;
+  }
+
   if(length $self->{data} >= $length) {
     $self->{obj}->content(substr($self->{data},0,$length,''));
     return 0;
@@ -323,7 +378,7 @@
       }
 
     } else {
-      die "expected chunked enoding, got '".substr($self->{data},0,40)."...'"
+      die "expected chunked encoding, got '".substr($self->{data},0,40)."...'"
        if $self->{data} =~ /\x0d?\x0a/;
       return -2;  # waiting for a line with chunk information
     }
@@ -354,6 +409,7 @@
 =head1 AUTHOR
 
 David Robins E<lt>dbrobins at davidrobins.netE<gt>
+Fixes for 0.05 by David Cannings E<lt>david at edeca.netE<gt>
 
 =head1 SEE ALSO
 

Modified: branches/upstream/libhttp-parser-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-perl/current/README?rev=59492&op=diff
==============================================================================
--- branches/upstream/libhttp-parser-perl/current/README (original)
+++ branches/upstream/libhttp-parser-perl/current/README Fri Jun 18 06:37:42 2010
@@ -9,15 +9,18 @@
 
 e.g.
 
+ use HTTP::Parser;
+
  my $parser = HTTP::Parser->new();
  my @lines = ('GET / HTTP/1.1','Host: localhost','Connection: close','','');
 
  my $result;
- while my $line(@lines) {
+ foreach my $line (@lines) {
    $result = $parser->add("$line\x0d\x0a");
    print "passing '$line' got '$result'\n";
  }
- print $result->as_string();
+ print $parser->object->as_string();
+
 
 gives:
 
@@ -48,6 +51,7 @@
 COPYRIGHT AND LICENCE
 
 Copyright (C) 2004-2007 David B. Robins
+Some fixes for 0.05 supplied by David Cannings
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself. 




More information about the Pkg-perl-cvs-commits mailing list