Skip to content

Commit 31cedf3

Browse files
committed
Zlib override and array of any curl options as parameters
instead of only timeout and maxredirs
1 parent 445e8b9 commit 31cedf3

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

proxy.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,24 @@
3434

3535
// Init curl
3636
$curl = curl_init();
37+
$maxredirs = $opts[CURLOPT_MAXREDIRS] ?? 20;
3738
do
3839
{
3940
// Set generic options
4041
curl_setopt_array($curl, [
4142
CURLOPT_URL => $url,
4243
CURLOPT_HTTPHEADER => $headers,
43-
CURLOPT_HEADER => TRUE,
44-
CURLOPT_TIMEOUT => $curl_timeout ?? 30,
45-
CURLOPT_FOLLOWLOCATION => TRUE,
46-
CURLOPT_MAXREDIRS => $curl_maxredirs ?? 10,
44+
CURLOPT_HEADER => true,
45+
] + $opts + [
46+
CURLOPT_FOLLOWLOCATION => true,
47+
CURLOPT_MAXREDIRS => $maxredirs,
4748
]);
4849

4950
// Method specific options
5051
switch($method)
5152
{
5253
case 'HEAD':
53-
curl_setopt($curl, CURLOPT_NOBODY, TRUE);
54+
curl_setopt($curl, CURLOPT_NOBODY, true);
5455
break;
5556

5657
case 'GET':

src/CrossOriginProxy.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ class CrossOriginProxy
1313
* Proxies the incoming request and outputs the response, including headers.
1414
*
1515
* @param whitelist Array of acceptable request URLs.
16-
* @param curl_timeout Timeout for the request.
17-
* @param curl_maxredirs Maximum number of allowed redirects.
16+
* @param curl_opts Array of cURL options to add to proxy request.
17+
* @param zlib Value for zlib.output_compression.
18+
*
19+
* @see http://php.net/manual/function.curl-setopt.php
20+
* @see http://php.net/manual/zlib.configuration.php
1821
*/
19-
public static function proxy(array $whitelist = [], int $curl_timeout = 30, int $curl_maxredirs = 10)
22+
public static function proxy(array $whitelist = [], array $curl_opts = [], $zlib = 'On')
2023
{
2124
require dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'proxy.php';
2225
}

0 commit comments

Comments
 (0)