1919use React \Stream \ThroughStream ;
2020use React \Http \Message \Uri ;
2121use Throwable ;
22+ use ValueError ;
2223use function array_change_key_case ;
2324use function array_key_exists ;
2425use function count ;
@@ -75,7 +76,6 @@ class Browser {
7576 //CURLOPT_HSTS_ENABLE => true, //PHP8.2
7677 ];
7778
78-
7979 protected array $ defaultHeaders = [
8080 'User-Agent ' => 'EdgeTelemetricsBrowser/1 ' ,
8181 ];
@@ -356,7 +356,7 @@ public function disableConnectionCaches() : void {
356356 private function initCurl () : CurlHandle {
357357 $ curl = curl_init ();
358358
359- if ($ curl === false || $ curl === null ) {
359+ if (! $ curl ) {
360360 throw new \RuntimeException ('Unable to init curl ' );
361361 }
362362
@@ -369,7 +369,16 @@ private function initCurl() : CurlHandle {
369369 curl_setopt ($ curl , CURLOPT_SHARE , $ this ->curlShare );
370370 }
371371
372- curl_setopt_array ($ curl , $ options );
372+ try {
373+ error_clear_last ();
374+ @curl_setopt_array ($ curl , $ options );
375+ if (error_get_last ()) {
376+ //Capture malformed options that result in conversion errors like "Array to string conversion"
377+ throw new \RuntimeException ('One or more cURL options values were invalid ' );
378+ }
379+ } catch (ValueError $ e ) {
380+ throw new \RuntimeException ('Invalid cURL options keys provided ' );
381+ }
373382
374383 return $ curl ;
375384 }
0 commit comments