HTTP-Parser-XS

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

      }
      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/response parser.

    The request parser can be used either for writing a synchronous HTTP
    server or a event-driven server.

lib/HTTP/Parser/XS.pm  view on Meta::CPAN

  }
  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/response parser.

The request parser can be used either for writing a synchronous HTTP server or a event-driven server.

t/02response.t  view on Meta::CPAN

}
----------
HTTP/1.0 200 OK
Content-Type: text/html

hogehoge
----------
{
 '_content' => "hogehoge\n",
 '_protocol' => 'HTTP/1.0',
 '_headers' => { "content-type" => "text/html"},
 '_rc' => 200,
 '_msg' => 'OK'
}
----------
HTTP/1.0 200 OK
Content-Type: text/html
X-Test: 1
X-Test: 2

hogehoge
----------
{
 '_content' => "hogehoge\n",
 '_protocol' => 'HTTP/1.0',
 '_headers' => { "content-type" => "text/html", "x-test" => [1,2]},
 '_rc' => 200,
 '_msg' => 'OK'
}
----------
HTTP/1.0 200 OK
Content-Type: text/html
X-Test: 1
 X-Test: 2

hogehoge
----------
{
 '_content' => "hogehoge\n",
 '_protocol' => 'HTTP/1.0',
 '_headers' => { "content-type" => "text/html", "x-test" => "1\n X-Test: 2"},
 '_rc' => 200,
 '_msg' => 'OK'
}
----------
HTTP/1.0 200 OK
Content-Type: text/html

----------
{
 '_content' => "",
 '_protocol' => 'HTTP/1.0',
 '_headers' => { "content-type" => "text/html"},
 '_rc' => 200,
 '_msg' => 'OK'
}
----------
HTTP/1.1 200 OK
Content-Type: text/html

----------
{
 '_content' => "",
 '_protocol' => 'HTTP/1.1',
 '_headers' => { "content-type" => "text/html"},
 '_rc' => 200,
 '_msg' => 'OK'
}
----------
HTTP/1.1 404 Not Found
Content-Type: text/html

----------
{
 '_content' => "",
 '_protocol' => 'HTTP/1.1',
 '_headers' => { "content-type" => "text/html"},
 '_rc' => 404,
 '_msg' => 'Not Found'
}
----------
HTTP/1.1 200 OK
Content-Type: text/html
FOO-BAR: BAZ

----------
{
 '_content' => "",
 '_protocol' => 'HTTP/1.1',
 '_headers' => { "content-type" => "text/html", "foo-bar" => 'BAZ'},
 '_rc' => 200,
 '_msg' => 'OK'
}
__HEADERS

my @tests = split '-'x10, $tests;
my $i = 0;
while (@tests) {
    $i++;
    my $header = shift @tests;

t/04response-format.t  view on Meta::CPAN

HTTP/1.0 200 OK

----------
{ ret => [17,"0","200","OK"], HEADER_AS_NONE => undef, HEADER_AS_HASH => {}, HEADER_AS_ARRAY => [] }
----------
HTTP/1.0 200 OK
Content-Type: text/html

hogehoge
----------
{ ret => [41,"0","200","OK"], HEADER_AS_NONE => undef, HEADER_AS_HASH => {"content-type" => "text/html"}, HEADER_AS_ARRAY => ["content-type","text/html"] }
----------
HTTP/1.0 200 OK
Content-Type: text/html
X-Test: 1
X-Test: 2

hogehoge
----------
{ ret => [61,"0","200","OK"], HEADER_AS_NONE => undef, HEADER_AS_HASH => {"content-type" => "text/html","x-test" => ["1","2"]}, HEADER_AS_ARRAY => ["content-type","text/html","x-test","1","x-test","2"] }
----------
HTTP/1.0 200 OK
Content-Type: text/html
X-Test: 1
 X-Test: 2

hogehoge
----------
{ ret => [62,"0","200","OK"], HEADER_AS_NONE => undef, HEADER_AS_HASH => {"content-type" => "text/html","x-test" => "1\n X-Test: 2"}, HEADER_AS_ARRAY => ["content-type","text/html","x-test","1\n X-Test: 2"] }
----------
HTTP/1.0 200 OK
Content-Type: text/html

----------
{ ret => [41,"0","200","OK"], HEADER_AS_NONE => undef, HEADER_AS_HASH => {"content-type" => "text/html"}, HEADER_AS_ARRAY => ["content-type","text/html"] }
----------
HTTP/1.1 200 OK
Content-Type: text/html

----------
{ ret => [41,"1","200","OK"], HEADER_AS_NONE => undef, HEADER_AS_HASH => {"content-type" => "text/html"}, HEADER_AS_ARRAY => ["content-type","text/html"] }
----------
HTTP/1.1 404 Not Found
Content-Type: text/html

----------
{ ret => [48,"1","404","Not Found"], HEADER_AS_NONE => undef, HEADER_AS_HASH => {"content-type" => "text/html"}, HEADER_AS_ARRAY => ["content-type","text/html"] }
----------
HTTP/1.1 200 OK
Content-Type: text/html
FOO-BAR: BAZ

----------
{ ret => [54,"1","200","OK"], HEADER_AS_NONE => undef, HEADER_AS_HASH => {"content-type" => "text/html","foo-bar" => "BAZ"}, HEADER_AS_ARRAY => ["content-type","text/html","foo-bar","BAZ"] }
__HEADERS

my @tests = split '-'x10, $tests;
my $i = 0;

while (@tests) {
    $i++;
    my $header = shift @tests;
    my $expect = shift @tests;
    $header =~ s/^\n//;



( run in 1.728 second using v1.01-cache-2.11-cpan-524268b4103 )