zendframework/zf2 — pull request #5608 by mschindler83 (2013-12-13 20:22:21+00:00)
Title: Http\Headers undefined index when calling ::fromString(' content-type: text/plain')

Hi,

This is my first contribution, so please try to be patient with me :)
When calling:

```
$headers = Zend\Http\Headers::fromString(' content-type: text/plain');
```

we get a

PHP Notice: Undefined index: line in /home/markus/projects/zf2/library/Zend/Http/Headers.php on line 74
PHP Notice: Undefined index: name in /home/markus/projects/zf2/library/Zend/Http/Headers.php on line 87

Would it be an option to throw an exception?

```
diff --git a/library/Zend/Http/Headers.php b/library/Zend/Http/Headers.php
index 6843fe1..b3ec64b 100644
--- a/library/Zend/Http/Headers.php
+++ b/library/Zend/Http/Headers.php
@@ -70,8 +70,16 @@ class Headers implements Countable, Iterator
'line' => trim($line)
);
} elseif (preg_match('/^\s+.*$/', $line, $matches)) {
- // continuation: append to current line
- $current['line'] .= trim($line);
+ if ($current) {
+ // continuation: append to current line
+ $current['line'] .= trim($line);
+ } else {
+ // Line does not match header format!
+ throw new Exception\RuntimeException(sprintf(
+ 'Line "%s" does not match header format!',
+ $line
+ ));
+ }
} elseif (preg_match('/^\s*$/', $line)) {
// empty line indicates end of headers
break;

```

Or maybe the first regex could match one or more whitespaces at the beginning

```
// check if a header name is present
if (preg_match('/^\s*(?P[^()><@,;:\"\\/\[\]?=}{ \t]+):.*$/', $line, $matches)) {
```

Or is it totally okay to get this notices?