Skip to content

Commit 1a189a6

Browse files
committed
Don't overwrite CURLOPT_HTTPHEADER option on WebClient if set
1 parent 342f550 commit 1a189a6

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/Clients/WebClient.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class WebClient extends Client
5454
protected $options =
5555
[
5656
CURLINFO_HEADER_OUT => true,
57+
CURLOPT_HTTPHEADER => [],
5758
CURLOPT_PUT => true,
5859
CURLOPT_RETURNTRANSFER => true,
5960
CURLOPT_TIMEOUT => 5,
@@ -213,7 +214,10 @@ public function request($type, $file = null)
213214
$options = $this->getCurlOptions($type, $file);
214215

215216
// sets headers
216-
$options[CURLOPT_HTTPHEADER] = $headers;
217+
foreach($headers as $header)
218+
{
219+
$options[CURLOPT_HTTPHEADER][] = $header;
220+
}
217221

218222
// cURL init and options
219223
$options[CURLOPT_URL] = "http://{$this->host}:{$this->port}" . "/$resource";

tests/BaseTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function testDocumentMainText($file)
216216

217217
if($client::MODE == 'web' && version_compare(self::$version, '1.15') < 0)
218218
{
219-
$this->markTestSkipped('Apache Tika ' . self::$version . 'lacks main content extraction');
219+
$this->markTestSkipped('Apache Tika ' . self::$version . ' lacks main content extraction');
220220
}
221221
else
222222
{
@@ -344,7 +344,7 @@ public function testMainTextCallback($file)
344344

345345
if($client::MODE == 'web' && version_compare(self::$version, '1.15') < 0)
346346
{
347-
$this->markTestSkipped('Apache Tika ' . self::$version . 'lacks main content extraction');
347+
$this->markTestSkipped('Apache Tika ' . self::$version . ' lacks main content extraction');
348348
}
349349
else
350350
{

tests/WebTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ public function testCurlOptions()
3030
$this->assertEquals(3, $options[CURLOPT_TIMEOUT]);
3131
}
3232

33+
/**
34+
* cURL headers test
35+
*/
36+
public function testCurlHeaders()
37+
{
38+
$header = 'Content-Type: image/jpeg';
39+
40+
$client = Client::make('localhost', 9998, [CURLOPT_HTTPHEADER => [$header]]);
41+
$options = $client->getOptions();
42+
43+
$this->assertContains($header, $options[CURLOPT_HTTPHEADER]);
44+
}
45+
3346
/**
3447
* Set host test
3548
*/

0 commit comments

Comments
 (0)