r52921 - in /branches/upstream/libhttp-parser-xs-perl: ./ current/ current/lib/ current/lib/HTTP/ current/lib/HTTP/Parser/ current/picohttpparser/ current/t/

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Wed Feb 17 01:40:13 UTC 2010


Author: jawnsy-guest
Date: Wed Feb 17 01:40:06 2010
New Revision: 52921

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=52921
Log:
[svn-inject] Installing original source of libhttp-parser-xs-perl

Added:
    branches/upstream/libhttp-parser-xs-perl/
    branches/upstream/libhttp-parser-xs-perl/current/
    branches/upstream/libhttp-parser-xs-perl/current/Changes
    branches/upstream/libhttp-parser-xs-perl/current/MANIFEST
    branches/upstream/libhttp-parser-xs-perl/current/META.yml
    branches/upstream/libhttp-parser-xs-perl/current/Makefile.PL
    branches/upstream/libhttp-parser-xs-perl/current/README
    branches/upstream/libhttp-parser-xs-perl/current/XS.xs
    branches/upstream/libhttp-parser-xs-perl/current/lib/
    branches/upstream/libhttp-parser-xs-perl/current/lib/HTTP/
    branches/upstream/libhttp-parser-xs-perl/current/lib/HTTP/Parser/
    branches/upstream/libhttp-parser-xs-perl/current/lib/HTTP/Parser/XS.pm
    branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/
    branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/picohttpparser.c
    branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/picohttpparser.h
    branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/test.c
    branches/upstream/libhttp-parser-xs-perl/current/t/
    branches/upstream/libhttp-parser-xs-perl/current/t/00base.t
    branches/upstream/libhttp-parser-xs-perl/current/t/01simple.t

Added: branches/upstream/libhttp-parser-xs-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/Changes?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/Changes (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/Changes Wed Feb 17 01:40:06 2010
@@ -1,0 +1,16 @@
+Revision history for Perl extension HTTP::Parser::XS.
+
+0.05  Fri Oct 23 21:12:00 2009
+	- no more (implicitly) depend on Exporter 5.63 (see http://rt.cpan.org/Public/Bug/Display.html?id=50607, thanks to ANDK for reporting)
+
+0.04  Fri Oct 16 08:15:00 2009
+	- fix memory leak (thanks to nothingmuch for writing the patch)
+
+0.03  Fri Oct 02 06:30:00 2009
+	- add REQUEST_URI to response
+
+0.02  Tue Sep 29 12:55:00 2009
+	- url-decode PATH_INFO
+
+0.01  Mon Sep 14 11:45:00 2009
+	- initial version

Added: branches/upstream/libhttp-parser-xs-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/MANIFEST?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/MANIFEST (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/MANIFEST Wed Feb 17 01:40:06 2010
@@ -1,0 +1,12 @@
+Changes
+lib/HTTP/Parser/XS.pm
+Makefile.PL
+MANIFEST			This list of files
+picohttpparser/picohttpparser.c
+picohttpparser/picohttpparser.h
+picohttpparser/test.c
+README
+t/00base.t
+t/01simple.t
+XS.xs
+META.yml                                 Module meta-data (added by MakeMaker)

Added: branches/upstream/libhttp-parser-xs-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/META.yml?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/META.yml (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/META.yml Wed Feb 17 01:40:06 2010
@@ -1,0 +1,21 @@
+--- #YAML:1.0
+name:               HTTP-Parser-XS
+version:            0.05
+abstract:           a fast, primitive HTTP request parser
+author:
+    - Kazuho Oku
+license:            unknown
+distribution_type:  module
+configure_requires:
+    ExtUtils::MakeMaker:  0
+build_requires:
+    ExtUtils::MakeMaker:  0
+requires:  {}
+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

Added: branches/upstream/libhttp-parser-xs-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/Makefile.PL?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/Makefile.PL (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/Makefile.PL Wed Feb 17 01:40:06 2010
@@ -1,0 +1,12 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME          => 'HTTP::Parser::XS',
+    VERSION_FROM  => 'lib/HTTP/Parser/XS.pm',
+    PREREQ_PM     => {},
+    ABSTRACT_FROM => 'lib/HTTP/Parser/XS.pm',
+    AUTHOR        => 'Kazuho Oku',
+    LIBS          => [],
+    DEFINE        => '',
+    INC           => '-I.',
+);

Added: branches/upstream/libhttp-parser-xs-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/README?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/README (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/README Wed Feb 17 01:40:06 2010
@@ -1,0 +1,1 @@
+see lib/HTTP/Parser/XS.pm

Added: branches/upstream/libhttp-parser-xs-perl/current/XS.xs
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/XS.xs?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/XS.xs (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/XS.xs Wed Feb 17 01:40:06 2010
@@ -1,0 +1,196 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+#include "picohttpparser/picohttpparser.c"
+
+#define MAX_HEADERS 128
+
+__inline char tou(char ch)
+{
+  if ('a' <= ch && ch <= 'z')
+    ch -= 'a' - 'A';
+  return ch;
+}
+
+static int header_is(const struct phr_header* header, const char* name,
+		     size_t len)
+{
+  const char* x, * y;
+  if (header->name_len != len)
+    return 0;
+  for (x = header->name, y = name; len != 0; --len, ++x, ++y)
+    if (tou(*x) != *y)
+      return 0;
+  return 1;
+}
+
+static size_t find_ch(const char* s, size_t len, char ch)
+{
+  size_t i;
+  for (i = 0; i != len; ++i, ++s)
+    if (*s == ch)
+      break;
+  return i;
+}
+
+__inline int hex_decode(const char ch)
+{
+  int r;
+  if ('0' <= ch && ch <= '9')
+    r = ch - '0';
+  else if ('A' <= ch && ch <= 'F')
+    r = ch - 'A' + 0xa;
+  else if ('a' <= ch && ch <= 'f')
+    r = ch - 'a' + 0xa;
+  else
+    r = -1;
+  return r;
+}
+
+static char* url_decode(const char* s, size_t len)
+{
+  char* dbuf, * d;
+  size_t i;
+  
+  for (i = 0; i < len; ++i)
+    if (s[i] == '%')
+      goto NEEDS_DECODE;
+  return (char*)s;
+  
+ NEEDS_DECODE:
+  dbuf = malloc(len - 1);
+  assert(dbuf != NULL);
+  memcpy(dbuf, s, i);
+  d = dbuf + i;
+  while (i < len) {
+    if (s[i] == '%') {
+      int hi, lo;
+      if ((hi = hex_decode(s[i + 1])) == -1
+	  || (lo = hex_decode(s[i + 2])) == -1)
+	return NULL;
+      *d++ = hi * 16 + lo;
+      i += 3;
+    } else
+      *d++ = s[i++];
+  }
+  *d = '\0';
+  return dbuf;
+}
+
+__inline int store_url_decoded(HV* env, const char* name, size_t name_len,
+			       const char* value, size_t value_len)
+{
+  char* decoded = url_decode(value, value_len);
+  if (decoded == NULL)
+    return -1;
+  
+  if (decoded == value)
+    hv_store(env, name, name_len, newSVpvn(value, value_len), 0);
+  else {
+    hv_store(env, name, name_len, newSVpv(decoded, 0), 0);
+    free(decoded);
+  }
+  return 0;
+}
+
+MODULE = HTTP::Parser::XS    PACKAGE = HTTP::Parser::XS
+
+int parse_http_request(SV* buf, SV* envref)
+PROTOTYPE: $$
+CODE:
+{
+  const char* buf_str;
+  STRLEN buf_len;
+  const char* method;
+  size_t method_len;
+  const char* path;
+  size_t path_len;
+  int minor_version;
+  struct phr_header headers[MAX_HEADERS];
+  size_t num_headers, question_at;
+  int ret, i;
+  HV* env;
+  SV* last_value;
+  char tmp[1024];
+  
+  buf_str = SvPV(buf, buf_len);
+  num_headers = MAX_HEADERS;
+  ret = phr_parse_request(buf_str, buf_len, &method, &method_len, &path,
+			  &path_len, &minor_version, headers, &num_headers, 0);
+  if (ret < 0)
+    goto done;
+  
+  env = (HV*)SvRV(envref);
+  if (SvTYPE(env) != SVt_PVHV)
+    Perl_croak(aTHX_ "second param to parse_http_request should be a hashref");
+  
+  hv_store(env, "REQUEST_METHOD", sizeof("REQUEST_METHOD") - 1,
+           newSVpvn(method, method_len), 0);
+  hv_store(env, "REQUEST_URI", sizeof("REQUEST_URI") - 1,
+	   newSVpvn(path, path_len), 0);
+  hv_store(env, "SCRIPT_NAME", sizeof("SCRIPT_NAME") - 1, newSVpvn("", 0), 0);
+  question_at = find_ch(path, path_len, '?');
+  if (store_url_decoded(env, "PATH_INFO", sizeof("PATH_INFO") - 1, path,
+			question_at)
+      != 0) {
+    hv_clear(env);
+    ret = -1;
+    goto done;
+  }
+  if (question_at != path_len)
+    ++question_at;
+  hv_store(env, "QUERY_STRING", sizeof("QUERY_STRING") - 1,
+	   newSVpvn(path + question_at, path_len - question_at), 0);
+  sprintf(tmp, "HTTP/1.%d", minor_version);
+  hv_store(env, "SERVER_PROTOCOL", sizeof("SERVER_PROTOCOL") - 1,
+           newSVpv(tmp, 0), 0);
+  last_value = NULL;
+  for (i = 0; i < num_headers; ++i) {
+    if (headers[i].name != NULL) {
+      const char* name;
+      size_t name_len;
+      SV** slot;
+      if (header_is(headers + i, "CONTENT-TYPE", sizeof("CONTENT-TYPE") - 1)) {
+	name = "CONTENT_TYPE";
+	name_len = sizeof("CONTENT_TYPE") - 1;
+      } else if (header_is(headers + i, "CONTENT-LENGTH",
+			   sizeof("CONTENT-LENGTH") - 1)) {
+	name = "CONTENT_LENGTH";
+	name_len = sizeof("CONTENT_LENGTH") - 1;
+      } else {
+	const char* s;
+	char* d;
+	size_t n;
+        if (sizeof(tmp) - 5 < headers[i].name_len) {
+	  hv_clear(env);
+          ret = -1;
+          goto done;
+        }
+        strcpy(tmp, "HTTP_");
+        for (s = headers[i].name, n = headers[i].name_len, d = tmp + 5;
+	     n != 0;
+	     s++, --n, d++)
+          *d = *s == '-' ? '_' : tou(*s);
+        name = tmp;
+        name_len = headers[i].name_len + 5;
+      }
+      slot = hv_fetch(env, name, name_len, 1);
+      if ( !slot )
+        croak("failed to create hash entry");
+      if (SvOK(*slot)) {
+        sv_catpvn(*slot, ", ", 2);
+        sv_catpvn(*slot, headers[i].value, headers[i].value_len);
+      } else
+        sv_setpvn(*slot, headers[i].value, headers[i].value_len);
+      last_value = *slot;
+    } else {
+      /* continuing lines of a mulitiline header */
+      sv_catpvn(last_value, headers[i].value, headers[i].value_len);
+    }
+  }
+  
+ done:
+  RETVAL = ret;
+}
+OUTPUT:
+  RETVAL

Added: branches/upstream/libhttp-parser-xs-perl/current/lib/HTTP/Parser/XS.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/lib/HTTP/Parser/XS.pm?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/lib/HTTP/Parser/XS.pm (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/lib/HTTP/Parser/XS.pm Wed Feb 17 01:40:06 2010
@@ -1,0 +1,94 @@
+package HTTP::Parser::XS;
+
+use strict;
+use warnings;
+
+use base qw(Exporter);
+
+our %EXPORT_TAGS = (
+    'all' => [ qw/parse_http_request/ ],
+);
+our @EXPORT_OK = @{$EXPORT_TAGS{all}};
+our @EXPORT = ();
+
+our $VERSION = '0.05';
+
+require XSLoader;
+XSLoader::load('HTTP::Parser::XS', $VERSION);
+
+1;
+__END__
+
+=head1 NAME
+
+HTTP::Parser::XS - a fast, primitive HTTP request parser
+
+=head1 SYNOPSIS
+
+  use HTTP::Parser::XS qw(parse_http_request);
+  
+  my $ret = parse_http_request(
+      "GET / HTTP/1.0\r\nHost: ...\r\n\r\n",
+      \%env,
+  );
+  if ($ret == -2) {
+      # request is incomplete
+      ...
+  } elsif ($ret == -1) {
+      # request is broken
+      ...
+  } else {
+      # $ret includes the size of the request, %env now contains a PSGI
+      # request, if it is a POST / PUT request, read request content by
+      # yourself
+      ...
+  }
+
+=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
+
+=over 4
+
+=item 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 refer to the PSGI specification.  The return values are:
+
+=over 8
+
+=item >=0
+
+length of the request (request line and the request headers), in bytes
+
+=item -1
+
+given request is corrupt
+
+=item -2
+
+given request is incomplete
+
+=back
+
+=back
+
+=head1 AUTHOR
+
+Kazuho Oku E<lt>kazuhooku at gmail.comE<gt>
+
+=head1 THANKS TO
+
+nothingmuch
+
+=head1 SEE ALSO
+
+L<HTTP::Parser>
+L<HTTP::HeaderParser::XS>
+
+=head1 LICENSE
+
+This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
+
+=cut

Added: branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/picohttpparser.c
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/picohttpparser.c?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/picohttpparser.c (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/picohttpparser.c Wed Feb 17 01:40:06 2010
@@ -1,0 +1,166 @@
+#include <stddef.h>
+#include "picohttpparser.h"
+
+#define CHECK_EOF()	\
+  if (buf == buf_end) { \
+    return -2;		\
+  }
+
+#define EXPECT(ch)    \
+  CHECK_EOF();	      \
+  if (*buf++ != ch) { \
+    return -1;	      \
+  }
+
+#define ADVANCE_TOKEN()			       \
+  for (; ; ++buf) {			       \
+    CHECK_EOF();			       \
+    if (*buf == ' ') {			       \
+      break;				       \
+    } else if (*buf == '\r' || *buf == '\n') { \
+      return -1;			       \
+    }					       \
+  }
+
+static int is_complete(const char* buf, const char* buf_end, size_t last_len)
+{
+  int ret_cnt = 0;
+  buf = last_len < 3 ? buf : buf + last_len - 3;
+  
+  while (1) {
+    CHECK_EOF();
+    if (*buf == '\r') {
+      ++buf;
+      CHECK_EOF();
+      EXPECT('\n');
+      ++ret_cnt;
+    } else if (*buf == '\n') {
+      ++buf;
+      ++ret_cnt;
+    } else {
+      ++buf;
+      ret_cnt = 0;
+    }
+    if (ret_cnt == 2) {
+      return 0;
+    }
+  }
+  
+  return -2;
+}
+
+int phr_parse_request(const char* _buf, size_t len, const char** method,
+		      size_t* method_len, const char** path, size_t* path_len,
+		      int* minor_version, struct phr_header* headers,
+		      size_t* num_headers, size_t last_len)
+{
+  const char * buf = _buf, * buf_end = buf + len;
+  size_t max_headers;
+  
+  /* if last_len != 0, check if the request is complete (a fast countermeasure
+     againt slowloris */
+  if (last_len != 0) {
+    int r = is_complete(buf, buf_end, last_len);
+    if (r != 0) {
+      return r;
+    }
+  }
+  
+  /* skip first empty line (some clients add CRLF after POST content) */
+  CHECK_EOF();
+  if (*buf == '\r') {
+    ++buf;
+    EXPECT('\n');
+  } else if (*buf == '\n') {
+    ++buf;
+  }
+  
+  /* parse request line */
+  *method = buf;
+  ADVANCE_TOKEN();
+  *method_len = buf - *method;
+  ++buf;
+  *path = buf;
+  ADVANCE_TOKEN();
+  *path_len = buf - *path;
+  ++buf;
+  EXPECT('H'); EXPECT('T'); EXPECT('T'); EXPECT('P'); EXPECT('/'); EXPECT('1');
+  EXPECT('.');
+  *minor_version = 0;
+  for (; ; ++buf) {
+    CHECK_EOF();
+    if ('0' <= *buf && *buf <= '9') {
+      *minor_version = *minor_version * 10 + *buf - '0';
+    } else {
+      break;
+    }
+  }
+  if (*buf == '\r') {
+    ++buf;
+    EXPECT('\n');
+  } else if (*buf == '\n') {
+    ++buf;
+  } else {
+    return -1;
+  }
+
+  /* parse headers */
+  max_headers = *num_headers;
+  for (*num_headers = 0; ; ++*num_headers) {
+    CHECK_EOF();
+    if (*buf == '\r') {
+      ++buf;
+      EXPECT('\n');
+      break;
+    } else if (*buf == '\n') {
+      ++buf;
+      break;
+    }
+    if (*num_headers == max_headers) {
+      return -1;
+    }
+    if (*num_headers == 0 || ! (*buf == ' ' || *buf == '\t')) {
+      /* parsing name */
+      headers[*num_headers].name = buf;
+      for (; ; ++buf) {
+	CHECK_EOF();
+	if (*buf == ':') {
+	  break;
+	} else if (*buf < ' ') {
+	  return -1;
+	}
+      }
+      headers[*num_headers].name_len = buf - headers[*num_headers].name;
+      ++buf;
+      for (; ; ++buf) {
+	CHECK_EOF();
+	if (! (*buf == ' ' || *buf == '\t')) {
+	  break;
+	}
+      }
+    } else {
+      headers[*num_headers].name = NULL;
+      headers[*num_headers].name_len = 0;
+    }
+    headers[*num_headers].value = buf;
+    for (; ; ++buf) {
+      CHECK_EOF();
+      if (*buf == '\r') {
+	headers[*num_headers].value_len = buf - headers[*num_headers].value;
+	++buf;
+	EXPECT('\n');
+	break;
+      } else if (*buf == '\n') {
+	headers[*num_headers].value_len = buf - headers[*num_headers].value;
+	++buf;
+	break;
+      }
+    }
+  }
+  
+  return buf - _buf;
+}
+
+#undef CHECK_EOF
+#undef EXPECT
+#undef ADVACE_TOKEN

Added: branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/picohttpparser.h
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/picohttpparser.h?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/picohttpparser.h (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/picohttpparser.h Wed Feb 17 01:40:06 2010
@@ -1,0 +1,21 @@
+#ifndef picohttpparser_h
+#define picohttpparser_h
+
+/* contains name and value of a header (name == NULL if is a continuing line
+ * of a multiline header */
+struct phr_header {
+  const char* name;
+  size_t name_len;
+  const char* value;
+  size_t value_len;
+};
+
+/* returns number of bytes cosumed if successful, -2 if request is partial,
+ * -1 if failed */
+int phr_parse_request(const char* buf, size_t len, const char** method,
+		      size_t* method_len, const char** path,
+		      size_t* path_len, int* minor_version,
+		      struct phr_header* headers, size_t* num_headers,
+		      size_t last_len);
+
+#endif

Added: branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/test.c
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/test.c?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/test.c (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/picohttpparser/test.c Wed Feb 17 01:40:06 2010
@@ -1,0 +1,83 @@
+#include <stdio.h>
+#include <string.h>
+#include "picohttpparser.h"
+
+void tests(int num)
+{
+  printf("1..%d\n", num);
+}
+
+void ok(int ok, const char* msg)
+{
+  static int testnum = 0;
+  printf("%s %d - %s\n", ok ? "ok" : "ng", ++testnum, msg);
+}
+
+int strrcmp(const char* s, size_t l, const char* t)
+{
+  return strlen(t) == l && memcmp(s, t, l) == 0;
+}
+
+int main(void)
+{
+  const char* method;
+  size_t method_len;
+  const char* path;
+  size_t path_len;
+  int minor_version;
+  struct phr_header headers[4];
+  size_t num_headers;
+  
+  tests(28);
+  
+#define PARSE(s, last_len, exp, comment)				\
+  num_headers = sizeof(headers) / sizeof(headers[0]);			\
+  ok(phr_parse_request(s, strlen(s), &method, &method_len, &path,	\
+		       &path_len, &minor_version, headers,		\
+		       &num_headers, last_len)				\
+    == (exp == 0 ? strlen(s) : exp),					\
+    comment)
+  
+  PARSE("GET / HTTP/1.0\r\n\r\n", 0, 0, "simple");
+  ok(num_headers == 0, "# of headers");
+  ok(strrcmp(method, method_len, "GET"), "method");
+  ok(strrcmp(path, path_len, "/"), "path");
+  ok(minor_version == 0, "minor version");
+  
+  PARSE("GET / HTTP/1.0\r\n\r", 0, -2, "partial");
+  
+  PARSE("GET /hoge HTTP/1.1\r\nHost: example.com\r\nCookie: \r\n\r\n", 0, 0,
+	"parse headers");
+  ok(num_headers == 2, "# of headers");
+  ok(strrcmp(method, method_len, "GET"), "method");
+  ok(strrcmp(path, path_len, "/hoge"), "path");
+  ok(minor_version == 1, "minor version");
+  ok(strrcmp(headers[0].name, headers[0].name_len, "Host"), "host");
+  ok(strrcmp(headers[0].value, headers[0].value_len, "example.com"),
+     "host value");
+  ok(strrcmp(headers[1].name, headers[1].name_len, "Cookie"), "cookie");
+  ok(strrcmp(headers[1].value, headers[1].value_len, ""), "cookie value");
+  
+  PARSE("GET / HTTP/1.0\r\nfoo: \r\nfoo: b\r\n  \tc\r\n\r\n", 0, 0,
+	"parse multiline");
+  ok(num_headers == 3, "# of headers");
+  ok(strrcmp(method, method_len, "GET"), "method");
+  ok(strrcmp(path, path_len, "/"), "path");
+  ok(minor_version == 0, "minor version");
+  ok(strrcmp(headers[0].name, headers[0].name_len, "foo"), "header #1 name");
+  ok(strrcmp(headers[1].value, headers[1].value_len, ""), "header #1 value");
+  ok(strrcmp(headers[1].name, headers[1].name_len, "foo"), "header #2 name");
+  ok(strrcmp(headers[1].value, headers[1].value_len, "b"), "header #2 value");
+  ok(headers[2].name == NULL, "header #3");
+  ok(strrcmp(headers[2].value, headers[2].value_len, "  \tc"),
+     "header #3 value");
+  
+  PARSE("GET /hoge HTTP/1.0\r\n\r", strlen("GET /hoge HTTP/1.0\r\n\r") - 1,
+	-2, "slowloris (incomplete)");
+  PARSE("GET /hoge HTTP/1.0\r\n\r\n", strlen("GET /hoge HTTP/1.0\r\n\r\n") - 1,
+	0, "slowloris (complete)");
+  
+#undef PARSE
+  
+  return 0;
+}

Added: branches/upstream/libhttp-parser-xs-perl/current/t/00base.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/t/00base.t?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/t/00base.t (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/t/00base.t Wed Feb 17 01:40:06 2010
@@ -1,0 +1,6 @@
+use Test::More tests => 1;
+
+BEGIN {
+    use_ok('HTTP::Parser::XS');
+}
+

Added: branches/upstream/libhttp-parser-xs-perl/current/t/01simple.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libhttp-parser-xs-perl/current/t/01simple.t?rev=52921&op=file
==============================================================================
--- branches/upstream/libhttp-parser-xs-perl/current/t/01simple.t (added)
+++ branches/upstream/libhttp-parser-xs-perl/current/t/01simple.t Wed Feb 17 01:40:06 2010
@@ -1,0 +1,100 @@
+use Test::More tests => 13;
+
+use HTTP::Parser::XS qw(parse_http_request);
+
+my $req;
+my %env;
+
+undef $@;
+eval {
+    parse_http_request("GET / HTTP/1.0\r\n\r\n", '');
+};
+ok($@, '"croak if second param is not a hashref');
+undef $@;
+
+$req = "GET /abc?x=%79 HTTP/1.0\r\n\r\n";
+%env = ();
+is(parse_http_request($req, \%env), length($req), 'simple get');
+is_deeply(\%env, {
+    PATH_INFO       => '/abc',
+    QUERY_STRING    => 'x=%79',
+    REQUEST_METHOD  => "GET",
+    REQUEST_URI     => '/abc?x=%79',
+    SCRIPT_NAME     => '',
+    SERVER_PROTOCOL => 'HTTP/1.0',
+}, 'result of GET /');
+
+$req = <<"EOT";
+POST /hoge HTTP/1.1\r
+Content-Type: text/plain\r
+Content-Length: 15\r
+Host: example.com\r
+User-Agent: hoge\r
+\r
+EOT
+%env = ();
+is(parse_http_request($req, \%env), length($req), 'POST');
+is_deeply(\%env, {
+    CONTENT_LENGTH  => 15,
+    CONTENT_TYPE    => 'text/plain',
+    HTTP_HOST       => 'example.com',
+    HTTP_USER_AGENT => 'hoge',
+    PATH_INFO       => '/hoge',
+    REQUEST_METHOD  => "POST",
+    REQUEST_URI     => '/hoge',
+    QUERY_STRING    => '',
+    SCRIPT_NAME     => '',
+    SERVER_PROTOCOL => 'HTTP/1.1',
+}, 'result of GET with headers');
+
+$req = <<"EOT";
+GET / HTTP/1.0\r
+Foo: \r
+Foo: \r
+  abc\r
+ de\r
+Foo: fgh\r
+\r
+EOT
+%env = ();
+is(parse_http_request($req, \%env), length($req), 'multiline header');
+is_deeply(\%env, {
+    HTTP_FOO        => ',   abc de, fgh',
+    PATH_INFO       => '/',
+    QUERY_STRING    => '',
+    REQUEST_METHOD  => 'GET',
+    REQUEST_URI     => '/',
+    SCRIPT_NAME     => '',
+    SERVER_PROTOCOL => 'HTTP/1.0',
+}, 'multiline');
+
+$req = <<"EOT";
+GET /a%20b HTTP/1.0\r
+\r
+EOT
+%env = ();
+is(parse_http_request($req, \%env), length($req), 'url-encoded');
+is_deeply(\%env, {
+    PATH_INFO      => '/a b',
+    REQUEST_METHOD => 'GET',
+    REQUEST_URI    => '/a%20b',
+    QUERY_STRING   => '',
+    SCRIPT_NAME     => '',
+    SERVER_PROTOCOL => 'HTTP/1.0',
+});
+
+$req = <<"EOT";
+GET /a%2zb HTTP/1.0\r
+\r
+EOT
+%env = ();
+is(parse_http_request($req, \%env), -1, 'invalid char in url-encoded path');
+is_deeply(\%env, {});
+
+$req = <<"EOT";
+GET /a%2 HTTP/1.0\r
+\r
+EOT
+%env = ();
+is(parse_http_request($req, \%env), -1, 'partially url-encoded');
+is_deeply(\%env, {});




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