--- /dev/null
+--TEST--
+header parser errors
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$headers = [
+ "Na\0me: value",
+ "Na\nme: value",
+ "Name:\0value",
+ "Name:\nvalue",
+ "Name: val\0ue",
+ "Name: value\0",
+];
+
+foreach ($headers as $header) {
+ $parsed = null;
+ $parser = new http\Header\Parser;
+ var_dump($parser->parse($header, http\Header\Parser::CLEANUP, $parsed), $parsed);
+}
+?>
+===DONE===
+--EXPECTF--
+Test
+
+Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected character '\000' at pos 2 of 'Na\000me' in %sheaderparser002.php on line %d
+int(-1)
+array(0) {
+}
+
+Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected end of line at pos 2 of 'Na\nme: value' in %sheaderparser002.php on line %d
+int(-1)
+array(0) {
+}
+
+Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected character '\000' at pos 0 of '\000value' in %sheaderparser002.php on line %d
+int(-1)
+array(0) {
+}
+
+Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected end of input at pos 5 of 'value' in %sheaderparser002.php on line %d
+int(-1)
+array(0) {
+}
+
+Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected character '\000' at pos 3 of 'val\000ue' in %sheaderparser002.php on line %d
+int(-1)
+array(0) {
+}
+
+Warning: http\Header\Parser::parse(): Failed to parse headers: unexpected character '\000' at pos 5 of 'value\000' in %sheaderparser002.php on line %d
+int(-1)
+array(0) {
+}
+===DONE===
\ No newline at end of file
--- /dev/null
+--TEST--
+header parser with nonblocking stream
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+echo "Test\n";
+
+$parser = new http\Header\Parser;
+$socket = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
+stream_set_blocking($socket[0], 0);
+
+$headers = [
+"GET / HTTP/1.1\n",
+"Host: localhost","\n",
+"Content","-length: 3\n",
+"\n",
+];
+
+while ($headers) {
+ $line = array_shift($headers);
+ $parser->stream($socket[0], 0, $hdrs);
+ fwrite($socket[1], $line);
+ var_dump($parser->getState());
+ var_dump($parser->stream($socket[0], 0, $hdrs));
+}
+
+var_dump($hdrs);
+
+?>
+DONE
+--EXPECT--
+Test
+int(0)
+int(1)
+int(1)
+int(2)
+int(2)
+int(3)
+int(3)
+int(1)
+int(1)
+int(3)
+int(3)
+int(5)
+array(2) {
+ ["Host"]=>
+ string(9) "localhost"
+ ["Content-Length"]=>
+ string(1) "3"
+}
+DONE