Created
July 12, 2021 13:14
-
-
Save btopro/d9b91f4453fac276fcc8aa6de43f02d2 to your computer and use it in GitHub Desktop.
Drupal 7 SSL connection issue with sockets; so force usage of curl if available.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Wrapper to leverage curl when possible to avoid potential socket connection | |
* issues with certain SSL connections | |
*/ | |
function _cis_connector_make_request($url, $options){ | |
// support developers overloading the request method, specifically curl | |
// as some systems can have issues with SSL configuration and socket connections | |
if (function_exists('curl_init')) { | |
$headers = array(); | |
foreach ($options['headers'] as $property => $value) { | |
$headers[] = $property . ': ' . $value; | |
} | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => $url, | |
CURLOPT_RETURNTRANSFER => TRUE, | |
CURLOPT_HEADER => TRUE, | |
CURLOPT_VERBOSE => TRUE, | |
CURLOPT_ENCODING => "", | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_TIMEOUT => 30, | |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |
CURLOPT_CUSTOMREQUEST => strtoupper($options['method']), | |
CURLOPT_HTTPHEADER => $headers, | |
CURLOPT_POSTFIELDS => "", | |
)); | |
$return = curl_exec($curl); | |
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); | |
$header = substr($return, 0, $header_size); | |
$rawheader = explode("\n", $header); | |
$body = substr($return, $header_size); | |
curl_close($curl); | |
$response = new stdClass(); | |
$response->data = $body; | |
foreach ($rawheader as $header) { | |
if (strpos($header, 'Link: ') === 0) { | |
$response->headers['link'] = str_replace('Link: ', '', $header); | |
} | |
} | |
} | |
// support for httprl which is faster then core and does same thing | |
elseif (module_exists('httprl')) { | |
httprl_request($url, $options); | |
// send the request off | |
$tmp = httprl_send_request(); | |
$response = array_pop($tmp); | |
} | |
else { | |
// original fallback | |
$response = drupal_http_request($url, $options); | |
} | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment