Skip to content

Commit f040699

Browse files
committed
fix empty Header can't iterate
1 parent 0cc46e4 commit f040699

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Qiniu/Http/Header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Header implements \ArrayAccess, \IteratorAggregate, \Countable
99
{
1010
/** @var array normalized key name map */
11-
private $data;
11+
private $data = array();
1212

1313
/**
1414
* @param array $obj non-normalized header object

tests/Qiniu/Tests/HeaderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,21 @@ public function testGetIterator()
145145
$this->assertFalse($hasException);
146146
}
147147

148+
public function testEmptyHeaderIterator()
149+
{
150+
$emptyHeader = new Header();
151+
152+
$hasException = false;
153+
try {
154+
foreach ($emptyHeader as $k => $v) {
155+
$hasException = !isset($header[$k]);
156+
}
157+
} catch (\Exception $e) {
158+
$hasException = true;
159+
}
160+
$this->assertFalse($hasException);
161+
}
162+
148163
public function testCount()
149164
{
150165
$header = new Header($this->heads);

0 commit comments

Comments
 (0)