From 2d8b4e466045e81fb7f77e25b2ccbd7f3ab44fe0 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Thu, 17 Aug 2017 14:08:38 +0200 Subject: fix basic authentication support in request_curl --- it_url.class | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'it_url.class') diff --git a/it_url.class b/it_url.class index 8b2ef51..1594f4c 100644 --- a/it_url.class +++ b/it_url.class @@ -283,17 +283,18 @@ function request($p=array()) static function curl_opts($p=array()) { $p += array('totaltimeout' => "999999", 'timeout' => 5); + $add = []; foreach ($p['headers'] as $header => $value) $headers[] = "$header: $value"; if ($p['maxlength']) { $maxlength = $p['maxlength']; - $add = array( + $add += [ #CURLOPT_BUFFERSIZE => 1024 * 1024 * 10, CURLOPT_NOPROGRESS => false, CURLOPT_PROGRESSFUNCTION => function ($dummy0, $dummy1, $size, $dummy2, $dummy3) use ($maxlength) { return $size < $maxlength ? 0 : 1; }, - ); + ]; } # file upload @@ -301,17 +302,15 @@ static function curl_opts($p=array()) $p['data'][$field] = new CURLFile($filename, mime_content_type($filename)); if ($p['data']) - $add[CURLOPT_POSTFIELDS] = $p['data']; + $add += [ CURLOPT_POSTFIELDS => $p['data'] ]; if ($p['compression']) - $add[CURLOPT_ENCODING] = ""; + $add += [ CURLOPT_ENCODING => "" ]; - if ($p['pass'] || $p['user']) { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_setopt($ch, CURLOPT_USERPWD, $p['user'] . ':' . $p['pass']); - } + if ($p['pass'] || $p['user']) + $add += [ CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => $p['user'] . ':' . $p['pass'] ]; - return (array)$add + array( + return $add + [ CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => $p['totaltimeout'], @@ -327,7 +326,7 @@ static function curl_opts($p=array()) CURLOPT_SSL_VERIFYHOST => $p['allow_insecure_ssl'] ? 0 : 2, CURLINFO_HEADER_OUT => 1, - ); + ]; } /* -- cgit v1.2.3