r65112 - in /trunk/libhttp-parser-xs-perl: ./ benchmark/ debian/ inc/ lib/HTTP/Parser/ lib/HTTP/Parser/XS/ t/

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Sat Nov 20 20:41:43 UTC 2010


Author: gregoa
Date: Sat Nov 20 20:41:35 2010
New Revision: 65112

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=65112
Log:
* New upstream release 0.12.

Added:
    trunk/libhttp-parser-xs-perl/benchmark/header_format.pl
      - copied unchanged from r65111, branches/upstream/libhttp-parser-xs-perl/current/benchmark/header_format.pl
    trunk/libhttp-parser-xs-perl/inc/
      - copied from r65111, branches/upstream/libhttp-parser-xs-perl/current/inc/
    trunk/libhttp-parser-xs-perl/lib/HTTP/Parser/XS/
      - copied from r65111, branches/upstream/libhttp-parser-xs-perl/current/lib/HTTP/Parser/XS/
    trunk/libhttp-parser-xs-perl/ppport.h
      - copied unchanged from r65111, branches/upstream/libhttp-parser-xs-perl/current/ppport.h
    trunk/libhttp-parser-xs-perl/t/02response.t
      - copied unchanged from r65111, branches/upstream/libhttp-parser-xs-perl/current/t/02response.t
    trunk/libhttp-parser-xs-perl/t/03response-error.t
      - copied unchanged from r65111, branches/upstream/libhttp-parser-xs-perl/current/t/03response-error.t
    trunk/libhttp-parser-xs-perl/t/04response-format.t
      - copied unchanged from r65111, branches/upstream/libhttp-parser-xs-perl/current/t/04response-format.t
    trunk/libhttp-parser-xs-perl/t/05too-much.t
      - copied unchanged from r65111, branches/upstream/libhttp-parser-xs-perl/current/t/05too-much.t
Modified:
    trunk/libhttp-parser-xs-perl/Changes
    trunk/libhttp-parser-xs-perl/MANIFEST
    trunk/libhttp-parser-xs-perl/META.yml
    trunk/libhttp-parser-xs-perl/Makefile.PL
    trunk/libhttp-parser-xs-perl/README
    trunk/libhttp-parser-xs-perl/XS.xs
    trunk/libhttp-parser-xs-perl/debian/changelog
    trunk/libhttp-parser-xs-perl/lib/HTTP/Parser/XS.pm
    trunk/libhttp-parser-xs-perl/t/00base.t

Modified: trunk/libhttp-parser-xs-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhttp-parser-xs-perl/Changes?rev=65112&op=diff
==============================================================================
--- trunk/libhttp-parser-xs-perl/Changes (original)
+++ trunk/libhttp-parser-xs-perl/Changes Sat Nov 20 20:41:35 2010
@@ -1,4 +1,14 @@
 Revision history for Perl extension HTTP::Parser::XS.
+
+0.12
+	- fix undeclared dependency on URI::Escape (RC #62716 thanks to ANDK for reporting)
+	- fix parsing of protocol version in the pure perl impl to exactly match that of XS
+
+0.11
+	- fix build error due to the use of Module::Install::ReadmeMarkdownFromPod (RT #62589)
+
+0.10
+	- support for HTTP response parsing (by gfx,mala,tokuhirom)
 
 0.09
 	- improve compatibility (mainly Windows, RT #61133, thanks to Taro Nishino)

Modified: trunk/libhttp-parser-xs-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhttp-parser-xs-perl/MANIFEST?rev=65112&op=diff
==============================================================================
--- trunk/libhttp-parser-xs-perl/MANIFEST (original)
+++ trunk/libhttp-parser-xs-perl/MANIFEST Sat Nov 20 20:41:35 2010
@@ -1,13 +1,30 @@
+benchmark/header_format.pl
 benchmark/simple.pl
 Changes
+inc/Module/Install.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/ReadmeFromPod.pm
+inc/Module/Install/TestTarget.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
 lib/HTTP/Parser/XS.pm
+lib/HTTP/Parser/XS/PP.pm
 Makefile.PL
 MANIFEST			This list of files
+META.yml
 picohttpparser/picohttpparser.c
 picohttpparser/picohttpparser.h
 picohttpparser/test.c
+ppport.h
 README
 t/00base.t
 t/01simple.t
+t/02response.t
+t/03response-error.t
+t/04response-format.t
+t/05too-much.t
 XS.xs
-META.yml                                 Module meta-data (added by MakeMaker)

Modified: trunk/libhttp-parser-xs-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhttp-parser-xs-perl/META.yml?rev=65112&op=diff
==============================================================================
--- trunk/libhttp-parser-xs-perl/META.yml (original)
+++ trunk/libhttp-parser-xs-perl/META.yml Sat Nov 20 20:41:35 2010
@@ -1,14 +1,24 @@
---- #YAML:1.0
-name:                HTTP-Parser-XS
-version:             0.09
-abstract:            a fast, primitive HTTP request parser
-license:             ~
-author:              
-    - Kazuho Oku
-generated_by:        ExtUtils::MakeMaker version 6.42
-distribution_type:   module
-requires:     
-    Test::More:                    0
+---
+abstract: 'a fast, primitive HTTP request parser'
+author:
+  - '- Kazuho Oku'
+  - 'Kazuho Oku'
+build_requires:
+  ExtUtils::MakeMaker: 6.42
+  Test::More: 0.96
+configure_requires:
+  ExtUtils::MakeMaker: 6.42
+distribution_type: module
+generated_by: 'Module::Install version 1.00'
+license: perl
 meta-spec:
-    url:     http://module-build.sourceforge.net/META-spec-v1.3.html
-    version: 1.3
+  url: http://module-build.sourceforge.net/META-spec-v1.4.html
+  version: 1.4
+name: HTTP-Parser-XS
+no_index:
+  directory:
+    - inc
+    - t
+resources:
+  license: http://dev.perl.org/licenses/
+version: 0.12

Modified: trunk/libhttp-parser-xs-perl/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhttp-parser-xs-perl/Makefile.PL?rev=65112&op=diff
==============================================================================
--- trunk/libhttp-parser-xs-perl/Makefile.PL (original)
+++ trunk/libhttp-parser-xs-perl/Makefile.PL Sat Nov 20 20:41:35 2010
@@ -1,30 +1,16 @@
-use ExtUtils::MakeMaker;
+use inc::Module::Install;
+use Module::Install::TestTarget;
 
-WriteMakefile(
-    NAME          => 'HTTP::Parser::XS',
-    VERSION_FROM  => 'lib/HTTP/Parser/XS.pm',
-    PREREQ_PM     => {
-	'Test::More' => 0,
-    },
-    ABSTRACT_FROM => 'lib/HTTP/Parser/XS.pm',
-    AUTHOR        => 'Kazuho Oku',
-    LIBS          => [],
-    DEFINE        => '',
-    INC           => '-I.',
+name 'HTTP-Parser-XS';
+all_from('lib/HTTP/Parser/XS.pm');
+readme_from('lib/HTTP/Parser/XS.pm');
+author 'Kazuho Oku';
+
+test_requires 'Test::More' => 0.96;
+
+test_target test_pp => (
+    env => { PERL_ONLY => 1 },
+	(alias => 'test')
 );
 
-eval {
-    require Pod::Text;
-    my $p = Pod::Text->new;
-    $p->output_fh(do {
-        open my $fh, '>', "README.$$" or die $!;
-        $fh;
-    });
-    $p->parse_file('lib/HTTP/Parser/XS.pm');
-    undef $p;
-    rename "README.$$", 'README'
-        or die $!;
-};
-
-print "Warning: no README, please install newest Pod::Text and rerun Makefile.PL\n"
-    unless -e 'README';
+WriteAll;

Modified: trunk/libhttp-parser-xs-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhttp-parser-xs-perl/README?rev=65112&op=diff
==============================================================================
--- trunk/libhttp-parser-xs-perl/README (original)
+++ trunk/libhttp-parser-xs-perl/README Sat Nov 20 20:41:35 2010
@@ -3,7 +3,8 @@
 
 SYNOPSIS
       use HTTP::Parser::XS qw(parse_http_request);
-  
+
+      # for HTTP servers
       my $ret = parse_http_request(
           "GET / HTTP/1.0\r\nHost: ...\r\n\r\n",
           \%env,
@@ -21,12 +22,45 @@
           ...
       }
 
+
+      # for HTTP clients
+      use HTTP::Parser::XS qw(parse_http_response HEADERS_AS_ARRAYREF);
+      my %special_headers = (
+        'content-length' => undef,
+      );
+      my($ret, $status, $message, $headers)
+        = parse_http_response($response, HEADERS_AS_ARRAYREF, \%special_headers);
+
+      if($ret == -1) }
+        # response is incomplete
+      }
+      elsif($ret == -2) {
+        # response is broken
+      }
+      else {
+        # $ret is the length of the headers, starting the content body
+
+        # the other values are the response messages. For example:
+        # $status  = 200
+        # $message = "OK"
+        # $headers = [ 'content-type' => 'text/html', ... ]
+
+        # and $special_headers{'content-length'} will be filled in
+      }
+
 DESCRIPTION
-    HTTP::Parser::XS is a fast, primitive HTTP request parser that can be
-    used either for writing a synchronous HTTP server or a event-driven
-    server.
+    HTTP::Parser::XS is a fast, primitive HTTP request/response parser.
 
-METHODS
+    The request parser can be used either for writing a synchronous HTTP
+    server or a event-driven server.
+
+    The response parser can be used for writing HTTP clients.
+
+    Note that even if this distribution name ends "::XS", pure Perl
+    implementation is supported, so you can use this module on compiler-less
+    environments.
+
+FUNCTIONS
     parse_http_request($request_string, \%env)
         Tries to parse given request string, and if successful, inserts
         variables into %env. For the name of the variables inserted, please
@@ -39,16 +73,75 @@
 
         -2      given request is incomplete
 
+    parse_http_response($response_string, $header_format, \%special_headers)
+        Tries to parse given response string. *$header_format* must be
+        "HEADERS_AS_ARRAYREF", "HEADERS_AS_HASHREF", or "HEADERS_NONE",
+        which are exportable constants.
+
+        The optional *%special_headers* is for headers you specifically
+        require. You can set any HTTP response header names, which must be
+        lower-cased, and their default values, and then the values are
+        filled in by "parse_http_response()". For example, if you want the
+        "Cointent-Length" field, set its name with default values like "%h =
+        ('content-length' => undef)" and pass it as *%special_headers*.
+        After parsing, $h{'content-length'} is set if the response has the
+        "Content-Length" field, otherwise it's not touched.
+
+        The return values are:
+
+        $ret    The parsering status, which is the same as
+                "parse_http_response()". i.e. the length of the response
+                headers in bytes, -1 for incomplete headers, or -2 for
+                errors.
+
+                If the given response string is broken or imcomplete,
+                "parse_http_response()" returns only this value.
+
+        $minor_version
+                The minor version of the given response. i.e. 1 for
+                HTTP/1.1, 0 for HTTP/1.0.
+
+        $status The HTTP status of the given response. e.g. 200 for success.
+
+        $message
+                The HTTP status message. e.g. "OK" for success.
+
+        $headers
+                The HTTP headers for the given response. It is an ARRAY
+                reference if *$header_format* is "HEADERS_AS_ARRAYREF", a
+                HASH reference on "HEADERS_AS_HASHREF", an "undef" on
+                "HEADERS_NONE".
+
+                The names of the headers are normalized to lower-cased.
+
+LIMITATIONS
+    Both "parse_http_request()" and "parse_http_response()" in XS
+    implementation have some size limitations.
+
+  The number of headers
+    The number of headers is limited to 128. If it exceeds, both parsing
+    routines report parsing errors, i.e. return -1 for $ret.
+
+  The size of header names
+    The size of header names is limited to 1024, but the parsers do not the
+    same action.
+
+    "parse_http_request()" returns -1 if too-long header names exist.
+
+    "parse_http_request()" simply ignores too-long header names.
+
 COPYRIGHT
     Copyright 2009- Kazuho Oku
 
 AUTHOR
-    Kazuho Oku
+    Kazuho Oku gfx mala tokuhirom
 
 THANKS TO
     nothingmuch charsbar
 
 SEE ALSO
+    <http://github.com/kazuho/picohttpparser>
+
     HTTP::Parser HTTP::HeaderParser::XS
 
 LICENSE

Modified: trunk/libhttp-parser-xs-perl/XS.xs
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhttp-parser-xs-perl/XS.xs?rev=65112&op=diff
==============================================================================
--- trunk/libhttp-parser-xs-perl/XS.xs (original)
+++ trunk/libhttp-parser-xs-perl/XS.xs Sat Nov 20 20:41:35 2010
@@ -2,17 +2,26 @@
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"
+#define NEED_newRV_noinc
+#define NEED_newSVpvn_flags
+#define NEED_sv_2pv_flags
+#include "ppport.h"
 #include "picohttpparser/picohttpparser.c"
 
 #ifndef STATIC_INLINE /* a public perl API from 5.13.4 */
-#   if defined(__GNUC__) || defined(__cplusplus__) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
+#   if defined(__GNUC__) || defined(__cplusplus) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
 #       define STATIC_INLINE static inline
 #   else
 #       define STATIC_INLINE static
 #   endif
 #endif /* STATIC_INLINE */
 
-#define MAX_HEADERS 128
+#define MAX_HEADER_NAME_LEN 1024
+#define MAX_HEADERS         128
+
+#define HEADERS_NONE        0
+#define HEADERS_AS_HASHREF  1
+#define HEADERS_AS_ARRAYREF 2
 
 STATIC_INLINE
 char tou(char ch)
@@ -20,6 +29,31 @@
   if ('a' <= ch && ch <= 'z')
     ch -= 'a' - 'A';
   return ch;
+}
+
+STATIC_INLINE char tol(char const ch)
+{
+  return ('A' <= ch && ch <= 'Z')
+    ? ch - ('A' - 'a')
+    : ch;
+}
+
+/* copy src to dest with normalization.
+   dest must have enough size for src */
+STATIC_INLINE
+void normalize_response_header_name(pTHX_
+        char* const dest,
+        const char* const src, STRLEN const len) {
+    STRLEN i;
+    for(i = 0; i < len; i++) {
+        dest[i] = tol(src[i]);
+    }
+}
+
+STATIC_INLINE
+void concat_multiline_header(pTHX_ SV * val, const char * const cont, size_t const cont_len) {
+    sv_catpvs(val, "\n"); /* XXX: is it collect? */
+    sv_catpvn(val, cont, cont_len);
 }
 
 static
@@ -73,7 +107,7 @@
   return (char*)s;
   
  NEEDS_DECODE:
-  dbuf = malloc(len - 1);
+  dbuf = (char*)malloc(len - 1);
   assert(dbuf != NULL);
   memcpy(dbuf, s, i);
   d = dbuf + i;
@@ -131,7 +165,7 @@
   int ret;
   HV* env;
   SV* last_value;
-  char tmp[1024];
+  char tmp[MAX_HEADER_NAME_LEN + sizeof("HTTP_") - 1];
   
   buf_str = SvPV(buf, buf_len);
   num_headers = MAX_HEADERS;
@@ -217,3 +251,120 @@
 }
 OUTPUT:
   RETVAL
+
+void
+parse_http_response(SV* buf, int header_format, HV* special_headers = NULL)
+PPCODE:
+{
+  int minor_version, status;
+  const char* msg;
+  size_t msg_len;
+  struct phr_header headers[MAX_HEADERS];
+  size_t num_headers = MAX_HEADERS;
+  STRLEN buf_len;
+  const char* const buf_str = SvPV_const(buf, buf_len);
+  size_t last_len = 0;
+  int const ret             = phr_parse_response(buf_str, buf_len,
+    &minor_version, &status, &msg, &msg_len, headers, &num_headers, last_len);
+  SV* last_special_headers_value_sv = NULL;
+  SV* last_element_value_sv         = NULL;
+  size_t i;
+  SV *res_headers;
+  char name[MAX_HEADER_NAME_LEN]; /* temp buffer for normalized names */
+
+  if (header_format == HEADERS_AS_HASHREF) {
+    res_headers = sv_2mortal((SV*)newHV());
+  } else if (header_format == HEADERS_AS_ARRAYREF) {
+    res_headers = sv_2mortal((SV*)newAV());
+    av_extend((AV*)res_headers, (num_headers * 2) - 1);
+  } else if (header_format == HEADERS_NONE) {
+    res_headers = NULL;
+  }
+
+  for (i = 0; i < num_headers; i++) {
+    struct phr_header const h = headers[i];
+    if (h.name != NULL) {
+      SV* namesv;
+      SV* valuesv;
+      if(h.name_len > sizeof(name)) {
+          /* skip if name_len is too long */
+          continue;
+      }
+
+      normalize_response_header_name(aTHX_
+        name, h.name, h.name_len);
+
+      if(special_headers) {
+          SV** const slot = hv_fetch(special_headers,
+            name, h.name_len, FALSE);
+          if (slot) {
+            SV* const hash_value = *slot;
+            sv_setpvn_mg(hash_value, h.value, h.value_len);
+            last_special_headers_value_sv = hash_value;
+          }
+          else {
+            last_special_headers_value_sv = NULL;
+          }
+      }
+
+      if(header_format == HEADERS_NONE) {
+          continue;
+      }
+
+      namesv  = sv_2mortal(newSVpvn_share(name, h.name_len, 0U));
+      valuesv = newSVpvn_flags(
+        h.value, h.value_len, SVs_TEMP);
+
+      if (header_format == HEADERS_AS_HASHREF) {
+        HE* const slot = hv_fetch_ent((HV*)res_headers, namesv, FALSE, 0U);
+        if(!slot) { /* first time */
+            (void)hv_store_ent((HV*)res_headers, namesv,
+                SvREFCNT_inc_simple_NN(valuesv), 0U);
+        }
+        else { /* second time; the header has multiple values */
+            SV* sv = hv_iterval((HV*)res_headers, slot);
+            if(!( SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVAV )) {
+                /* make $value to [$value] and restore it to $res_header */
+                AV* const av    = newAV();
+                SV* const avref = newRV_noinc((SV*)av);
+                (void)av_store(av, 0, SvREFCNT_inc_simple_NN(sv));
+                (void)hv_store_ent((HV*)res_headers, namesv, avref, 0U);
+                sv = avref;
+            }
+            av_push((AV*)SvRV(sv), SvREFCNT_inc_simple_NN(valuesv));
+        }
+        last_element_value_sv = valuesv;
+      } else if (header_format == HEADERS_AS_ARRAYREF) {
+            av_push((AV*)res_headers, SvREFCNT_inc_simple_NN(namesv));
+            av_push((AV*)res_headers, SvREFCNT_inc_simple_NN(valuesv));
+            last_element_value_sv = valuesv;
+      }
+    } else {
+      /* continuing lines of a mulitiline header */
+      if (special_headers && last_special_headers_value_sv) {
+        concat_multiline_header(aTHX_ last_special_headers_value_sv, h.value, h.value_len);
+      }
+      if ((header_format == HEADERS_AS_HASHREF || header_format == HEADERS_AS_ARRAYREF) && last_element_value_sv) {
+        concat_multiline_header(aTHX_ last_element_value_sv, h.value, h.value_len);
+      }
+    }
+  }
+  
+  if(ret > 0) {
+    EXTEND(SP, 5);
+    mPUSHi(ret);
+    mPUSHi(minor_version);
+    mPUSHi(status);
+    mPUSHp(msg, msg_len);
+    if (res_headers) {
+      mPUSHs(newRV_inc(res_headers));
+    } else {
+      mPUSHs(&PL_sv_undef);
+    }
+  }
+  else {
+    EXTEND(SP, 1);
+    mPUSHi(ret);
+  }
+}
+

Modified: trunk/libhttp-parser-xs-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhttp-parser-xs-perl/debian/changelog?rev=65112&op=diff
==============================================================================
--- trunk/libhttp-parser-xs-perl/debian/changelog (original)
+++ trunk/libhttp-parser-xs-perl/debian/changelog Sat Nov 20 20:41:35 2010
@@ -1,11 +1,12 @@
-libhttp-parser-xs-perl (0.09-1) UNRELEASED; urgency=low
+libhttp-parser-xs-perl (0.12-1) UNRELEASED; urgency=low
 
-  Improved compatibility for Solaris + Windows
-  IGNORE-VERSION: 0.09-1
+  [ Jonathan Yu ]
+  * New upstream release 0.09
 
-  * New upstream release
+  [ gregor herrmann ]
+  * New upstream release 0.12.
 
- -- Jonathan Yu <jawnsy at cpan.org>  Sun, 03 Oct 2010 15:10:26 -0400
+ -- gregor herrmann <gregoa at debian.org>  Sat, 20 Nov 2010 21:39:56 +0100
 
 libhttp-parser-xs-perl (0.07-1) unstable; urgency=low
 

Modified: trunk/libhttp-parser-xs-perl/lib/HTTP/Parser/XS.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhttp-parser-xs-perl/lib/HTTP/Parser/XS.pm?rev=65112&op=diff
==============================================================================
--- trunk/libhttp-parser-xs-perl/lib/HTTP/Parser/XS.pm (original)
+++ trunk/libhttp-parser-xs-perl/lib/HTTP/Parser/XS.pm Sat Nov 20 20:41:35 2010
@@ -6,15 +6,38 @@
 use base qw(Exporter);
 
 our %EXPORT_TAGS = (
-    'all' => [ qw/parse_http_request/ ],
+    'all' => [ qw/parse_http_request parse_http_response
+                  HEADERS_NONE HEADERS_AS_HASHREF HEADERS_AS_ARRAYREF/ ],
 );
 our @EXPORT_OK = @{$EXPORT_TAGS{all}};
 our @EXPORT = ();
 
-our $VERSION = '0.09';
-
-require XSLoader;
-XSLoader::load('HTTP::Parser::XS', $VERSION);
+# header format for parse_http_response()
+use constant {
+    HEADERS_NONE => 0,       # don't parse headers. It's fastest. if you want only special headers, also fastest.
+    HEADERS_AS_HASHREF => 1,    # HTTP::Headers compatible HashRef, { header_name => "header_value" or ["val1", "val2"] }
+    HEADERS_AS_ARRAYREF =>2,    # Ordered ArrayRef : [ name, value, name2, value2 ... ]
+};
+
+our $VERSION = '0.12';
+
+our $BACKEND;
+
+if (not __PACKAGE__->can('parse_http_response')) {
+    $BACKEND = $ENV{PERL_HTTP_PARSER_XS} || ($ENV{PERL_ONLY} ? 'pp' : '');
+    if ($BACKEND !~ /\b pp \b/xms) {
+        eval {
+            require XSLoader;
+            XSLoader::load(__PACKAGE__, $VERSION);
+            $BACKEND = 'xs';
+        };
+        die $@ if $@ && $BACKEND =~ /\bxs\b/;
+    }
+    if (not __PACKAGE__->can('parse_http_response')) {
+        require HTTP::Parser::XS::PP;
+        $BACKEND = 'pp';
+    }
+}
 
 1;
 __END__
@@ -26,7 +49,8 @@
 =head1 SYNOPSIS
 
   use HTTP::Parser::XS qw(parse_http_request);
-  
+
+  # for HTTP servers
   my $ret = parse_http_request(
       "GET / HTTP/1.0\r\nHost: ...\r\n\r\n",
       \%env,
@@ -44,11 +68,46 @@
       ...
   }
 
+
+  # for HTTP clients
+  use HTTP::Parser::XS qw(parse_http_response HEADERS_AS_ARRAYREF);
+  my %special_headers = (
+    'content-length' => undef,
+  );
+  my($ret, $status, $message, $headers)
+    = parse_http_response($response, HEADERS_AS_ARRAYREF, \%special_headers);
+
+  if($ret == -1) }
+    # response is incomplete
+  }
+  elsif($ret == -2) {
+    # response is broken
+  }
+  else {
+    # $ret is the length of the headers, starting the content body
+
+    # the other values are the response messages. For example:
+    # $status  = 200
+    # $message = "OK"
+    # $headers = [ 'content-type' => 'text/html', ... ]
+
+    # and $special_headers{'content-length'} will be filled in
+  }
+
+
 =head1 DESCRIPTION
 
-HTTP::Parser::XS is a fast, primitive HTTP request parser that can be used either for writing a synchronous HTTP server or a event-driven server.
-
-=head1 METHODS
+HTTP::Parser::XS is a fast, primitive HTTP request/response parser.
+
+The request parser can be used either for writing a synchronous HTTP server or a event-driven server.
+
+The response parser can be used for writing HTTP clients.
+
+Note that even if this distribution name ends C<::XS>, B<pure Perl>
+implementation is supported, so you can use this module on compiler-less
+environments.
+
+=head1 FUNCTIONS
 
 =over 4
 
@@ -72,8 +131,78 @@
 
 =back
 
+=item parse_http_response($response_string, $header_format, \%special_headers)
+
+Tries to parse given response string. I<$header_format> must be
+C<HEADERS_AS_ARRAYREF>, C<HEADERS_AS_HASHREF>, or C<HEADERS_NONE>,
+which are exportable constants.
+
+The optional I<%special_headers> is for headers you specifically require.
+You can set any HTTP response header names, which must be lower-cased,
+and their default values, and then the values are filled in by
+C<parse_http_response()>.
+For example, if you want the C<Cointent-Length> field, set its name with
+default values like C<< %h = ('content-length' => undef) >> and pass it as
+I<%special_headers>. After parsing, C<$h{'content-length'}> is set
+if the response has the C<Content-Length> field, otherwise it's not touched.
+
+The return values are:
+
+=over 8
+
+=item C<$ret>
+
+The parsering status, which is the same as C<parse_http_response()>. i.e.
+the length of the response headers in bytes, C<-1> for incomplete headers,
+or C<-2> for errors.
+
+If the given response string is broken or imcomplete, C<parse_http_response()>
+returns only this value.
+
+=item C<$minor_version>
+
+The minor version of the given response.
+i.e. C<1> for HTTP/1.1, C<0> for HTTP/1.0.
+
+=item C<$status>
+
+The HTTP status of the given response. e.g. C<200> for success.
+
+=item C<$message>
+
+The HTTP status message. e.g. C<OK> for success.
+
+=item C<$headers>
+
+The HTTP headers for the given response. It is an ARRAY reference
+if I<$header_format> is C<HEADERS_AS_ARRAYREF>, a HASH reference on
+C<HEADERS_AS_HASHREF>, an C<undef> on C<HEADERS_NONE>.
+
+The names of the headers are normalized to lower-cased.
+
 =back
 
+=back
+
+=head1 LIMITATIONS
+
+Both C<parse_http_request()> and C<parse_http_response()> in XS
+implementation have some size limitations.
+
+=head2 The number of headers
+
+The number of headers is limited to C<128>. If it exceeds, both parsing
+routines report parsing errors, i.e. return C<-1> for C<$ret>.
+
+=head2 The size of header names
+
+The size of header names is limited to C<1024>, but the parsers do not the
+same action.
+
+C<parse_http_request()> returns C<-1> if too-long header names exist.
+
+C<parse_http_request()> simply ignores too-long header names.
+
 =head1 COPYRIGHT
 
 Copyright 2009- Kazuho Oku
@@ -81,6 +210,9 @@
 =head1 AUTHOR
 
 Kazuho Oku
+gfx
+mala
+tokuhirom
 
 =head1 THANKS TO
 
@@ -89,6 +221,8 @@
 
 =head1 SEE ALSO
 
+L<http://github.com/kazuho/picohttpparser>
+
 L<HTTP::Parser>
 L<HTTP::HeaderParser::XS>
 

Modified: trunk/libhttp-parser-xs-perl/t/00base.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhttp-parser-xs-perl/t/00base.t?rev=65112&op=diff
==============================================================================
--- trunk/libhttp-parser-xs-perl/t/00base.t (original)
+++ trunk/libhttp-parser-xs-perl/t/00base.t Sat Nov 20 20:41:35 2010
@@ -3,4 +3,5 @@
 BEGIN {
     use_ok('HTTP::Parser::XS');
 }
-
+diag "Testing HTTP::Parser::XS/$HTTP::Parser::XS::VERSION",
+     " ($HTTP::Parser::XS::BACKEND)";




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