@@ -492,12 +492,13 @@ function replace_path_consts( $source, $path ) {
492492 * @param string $method HTTP method (GET, POST, DELETE, etc.)
493493 * @param string $url URL to make the HTTP request to.
494494 * @param array $headers Add specific headers to the request.
495+ * @param array $data
495496 * @param array $options
496497 * @return object
497498 */
498499function http_request ( $ method , $ url , $ data = null , $ headers = array (), $ options = array () ) {
499500
500- $ cert_path = '/rmccue/requests/library/Requests/Transport /cacert.pem ' ;
501+ $ cert_path = '/rmccue/requests/certificates /cacert.pem ' ;
501502 $ halt_on_error = ! isset ( $ options ['halt_on_error ' ] ) || (bool ) $ options ['halt_on_error ' ];
502503 if ( inside_phar () ) {
503504 // cURL can't read Phar archives
@@ -521,23 +522,31 @@ function http_request( $method, $url, $data = null, $headers = array(), $options
521522 }
522523
523524 try {
524- return \Requests::request ( $ url , $ headers , $ data , $ method , $ options );
525- } catch ( \Requests_Exception $ ex ) {
526- // CURLE_SSL_CACERT_BADFILE only defined for PHP >= 7.
527- if ( 'curlerror ' !== $ ex ->getType () || ! in_array ( curl_errno ( $ ex ->getData () ), array ( CURLE_SSL_CONNECT_ERROR , CURLE_SSL_CERTPROBLEM , 77 /*CURLE_SSL_CACERT_BADFILE*/ ), true ) ) {
528- $ error_msg = sprintf ( "Failed to get url '%s': %s. " , $ url , $ ex ->getMessage () );
529- if ( $ halt_on_error ) {
530- EE ::error ( $ error_msg );
531- }
532- throw new \RuntimeException ( $ error_msg , null , $ ex );
533- }
525+ // Updated class name: \WpOrg\Requests\Requests
526+ $ response = \WpOrg \Requests \Requests::request ( $ url , $ headers , $ data , $ method , $ options );
527+ return $ response ;
528+ } catch ( \WpOrg \Requests \Exception $ ex ) { // Updated exception class name
529+
534530 // Handle SSL certificate issues gracefully
535- \EE ::warning ( sprintf ( "Re-trying without verify after failing to get verified url '%s' %s. " , $ url , $ ex ->getMessage () ) );
536- $ options ['verify ' ] = false ;
537- try {
538- return \Requests::request ( $ url , $ headers , $ data , $ method , $ options );
539- } catch ( \Requests_Exception $ ex ) {
540- $ error_msg = sprintf ( "Failed to get non-verified url '%s' %s. " , $ url , $ ex ->getMessage () );
531+ $ curl_error = false ;
532+ if ( $ ex instanceof \WpOrg \Requests \Exception \Transport \Curl ) {
533+ $ curl_error = true ;
534+ }
535+
536+ if ( $ curl_error && in_array ( $ ex ->getCode (), array ( CURLE_SSL_CONNECT_ERROR , CURLE_SSL_CERTPROBLEM , 77 /*CURLE_SSL_CACERT_BADFILE*/ ), true ) ) {
537+ \EE ::warning ( sprintf ( "Re-trying without verify after failing to get verified url '%s' %s. " , $ url , $ ex ->getMessage () ) );
538+ $ options ['verify ' ] = false ;
539+ try {
540+ return \WpOrg \Requests \Requests::request ( $ url , $ headers , $ data , $ method , $ options );
541+ } catch ( \WpOrg \Requests \Exception $ ex ) {
542+ $ error_msg = sprintf ( "Failed to get non-verified url '%s' %s. " , $ url , $ ex ->getMessage () );
543+ if ( $ halt_on_error ) {
544+ EE ::error ( $ error_msg );
545+ }
546+ throw new \RuntimeException ( $ error_msg , null , $ ex );
547+ }
548+ } else {
549+ $ error_msg = sprintf ( "Failed to get url '%s': %s. " , $ url , $ ex ->getMessage () );
541550 if ( $ halt_on_error ) {
542551 EE ::error ( $ error_msg );
543552 }
0 commit comments