@@ -375,13 +375,16 @@ public static function wrapResult($result = '', $queryObject = '')
375375 *
376376 * @return Result
377377 * */
378- public static function contentstackRequest ($ queryObject = '' , $ type = '' )
378+ public static function contentstackRequest ($ stack , $ queryObject = '' , $ type = '' , $ count = 0 )
379379 {
380380 $ server_output = '' ;
381381 STATIC $ live_response_decode = '' ;
382382 STATIC $ entry_uid = '' ;
383383 STATIC $ content_type_uid = '' ;
384384
385+ $ retryDelay = $ stack ->retryDelay ;
386+ $ retryLimit = $ stack ->retryLimit ;
387+ $ errorRetry = $ stack ->errorRetry ;
385388 if ($ queryObject ) {
386389 if (Utility::isLivePreview ($ queryObject )) {
387390 $ queryObject ->_query ['live_preview ' ] = ($ queryObject ->contentType ->stack ->live_preview ['live_preview ' ] ?? 'init ' );
@@ -402,22 +405,57 @@ public static function contentstackRequest($queryObject = '', $type = '')
402405 if ($ Headers ["branch " ] !== '' && $ Headers ["branch " ] !== "undefined " ) {
403406 $ request_headers [] = 'branch: ' .$ Headers ["branch " ];
404407 }
408+
409+ $ proxy_details = $ stack ->proxy ;
410+ $ timeout = $ stack ->timeout ;
411+
405412 curl_setopt ($ http , CURLOPT_HTTPHEADER , $ request_headers );
406413
407414 curl_setopt ($ http , CURLOPT_HEADER , false );
408415 // setting the GET request
409416 curl_setopt ($ http , CURLOPT_CUSTOMREQUEST , "GET " );
410417 // receive server response ...
411418 curl_setopt ($ http , CURLOPT_RETURNTRANSFER , true );
412- $ response = curl_exec ($ http );
419+ // set the cURL time out
420+ curl_setopt ($ http , CURLOPT_TIMEOUT_MS , $ timeout );
413421
422+ if (array_key_exists ("url " ,$ proxy_details ) && array_key_exists ("port " ,$ proxy_details )){
423+ if ($ proxy_details ['url ' ] != '' && $ proxy_details ['port ' ] != '' ) {
424+
425+ // Set the proxy IP
426+ curl_setopt ($ http , CURLOPT_PROXY , $ proxy_details ['url ' ]);
427+ // Set the port
428+ curl_setopt ($ http , CURLOPT_PROXYPORT , $ proxy_details ['port ' ]);
429+
430+ if (array_key_exists ("username " ,$ proxy_details ) && array_key_exists ("password " ,$ proxy_details )){
431+ if ($ proxy_details ['username ' ] != '' && $ proxy_details ['password ' ] != '' ) {
432+
433+ $ proxyauth = $ proxy_details ['username ' ].": " .$ proxy_details ['password ' ];
434+ // Set the username and password
435+ curl_setopt ($ http , CURLOPT_PROXYUSERPWD , $ proxyauth );
436+
437+ }
438+ }
439+ }
440+ }
441+
442+ $ response = curl_exec ($ http );
414443 // status code extraction
415444 $ httpcode = curl_getinfo ($ http , CURLINFO_HTTP_CODE );
416-
445+
417446 // close the curl
418447 curl_close ($ http );
419- if ($ httpcode > 199 && $ httpcode < 300 ) {
420- if (!Utility::isLivePreview ($ queryObject )) {
448+
449+ if (in_array ($ httpcode ,$ errorRetry )){
450+ if ($ count < $ retryLimit ){
451+ $ retryDelay = round ($ retryDelay /1000 ); //converting retry_delay from milliseconds into seconds
452+ sleep ($ retryDelay ); //sleep method requires time in seconds
453+ $ count += 1 ;
454+ return Utility::contentstackRequest ($ stack , $ queryObject , $ type , $ count );
455+ }
456+ } else {
457+ if ($ httpcode > 199 && $ httpcode < 300 ) {
458+ if (!Utility::isLivePreview ($ queryObject )) {
421459 $ result = json_decode ($ response , true );
422460 Utility::to_render_content ($ result , $ entry_uid , $ live_response_decode );
423461 $ response = json_encode ($ result , true );
@@ -430,15 +468,19 @@ public static function contentstackRequest($queryObject = '', $type = '')
430468 $ live_response_decode = json_decode ($ response , true );
431469
432470 }
433- // wrapper the server result
434- $ response = Utility::wrapResult ($ response , $ queryObject );
435- } else {
436- throw new CSException ($ response , $ httpcode );
471+ // wrapper the server result
472+ $ response = Utility::wrapResult ($ response , $ queryObject );
473+ }
474+ else {
475+ throw new CSException ($ response , $ httpcode );
476+ }
437477 }
438478 }
479+
439480 return $ response ;
440481 }
441482
483+
442484 public static function to_render_content (&$ resp , $ entry_uid , $ live_response_decode ){
443485 if (is_array ($ resp )) {
444486 if (array_key_exists ('uid ' , $ resp ) && $ resp ['uid ' ] == $ entry_uid ){
@@ -452,6 +494,7 @@ public static function to_render_content(&$resp, $entry_uid, $live_response_deco
452494 }
453495 }
454496
497+
455498 /**
456499 * Validate the key is set or not
457500 *
0 commit comments