Skip to content

Commit b48462d

Browse files
authored
Merge pull request paquettg#201 from hmerritt/master
Add custom headers to curl request
2 parents 02b2d0c + 8a551cc commit b48462d

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/PHPHtmlParser/Curl.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@ class Curl implements CurlInterface
1515
* A simple curl implementation to get the content of the url.
1616
*
1717
* @param string $url
18+
* @param array $options
1819
* @return string
1920
* @throws CurlException
2021
*/
21-
public function get(string $url): string
22+
public function get(string $url, array $options): string
2223
{
2324
$ch = curl_init($url);
2425

2526
if ( ! ini_get('open_basedir')) {
2627
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
2728
}
2829

30+
if (isset($options['curlHeaders'])) {
31+
curl_setopt($ch, CURLOPT_HTTPHEADER, $options['curlHeaders']);
32+
}
33+
2934
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
3035
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
3136
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

src/PHPHtmlParser/CurlInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ interface CurlInterface
1313
* This method should return the content of the url in a string
1414
*
1515
* @param string $url
16+
* @param array $options
1617
* @return string
1718
*/
18-
public function get(string $url): string;
19+
public function get(string $url, array $options): string;
1920
}

src/PHPHtmlParser/Dom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function loadFromUrl(string $url, array $options = [], CurlInterface $cur
191191
// use the default curl interface
192192
$curl = new Curl;
193193
}
194-
$content = $curl->get($url);
194+
$content = $curl->get($url, $options);
195195

196196
return $this->loadStr($content, $options);
197197
}

0 commit comments

Comments
 (0)