@@ -375,13 +375,16 @@ public static function wrapResult($result = '', $queryObject = '')
375
375
*
376
376
* @return Result
377
377
* */
378
- public static function contentstackRequest ($ queryObject = '' , $ type = '' )
378
+ public static function contentstackRequest ($ stack , $ queryObject = '' , $ type = '' , $ count = 0 )
379
379
{
380
380
$ server_output = '' ;
381
381
STATIC $ live_response_decode = '' ;
382
382
STATIC $ entry_uid = '' ;
383
383
STATIC $ content_type_uid = '' ;
384
384
385
+ $ retryDelay = $ stack ->retryDelay ;
386
+ $ retryLimit = $ stack ->retryLimit ;
387
+ $ errorRetry = $ stack ->errorRetry ;
385
388
if ($ queryObject ) {
386
389
if (Utility::isLivePreview ($ queryObject )) {
387
390
$ queryObject ->_query ['live_preview ' ] = ($ queryObject ->contentType ->stack ->live_preview ['live_preview ' ] ?? 'init ' );
@@ -402,22 +405,57 @@ public static function contentstackRequest($queryObject = '', $type = '')
402
405
if ($ Headers ["branch " ] !== '' && $ Headers ["branch " ] !== "undefined " ) {
403
406
$ request_headers [] = 'branch: ' .$ Headers ["branch " ];
404
407
}
408
+
409
+ $ proxy_details = $ stack ->proxy ;
410
+ $ timeout = $ stack ->timeout ;
411
+
405
412
curl_setopt ($ http , CURLOPT_HTTPHEADER , $ request_headers );
406
413
407
414
curl_setopt ($ http , CURLOPT_HEADER , false );
408
415
// setting the GET request
409
416
curl_setopt ($ http , CURLOPT_CUSTOMREQUEST , "GET " );
410
417
// receive server response ...
411
418
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 );
413
421
422
+ if (array_***_exists ("url " ,$ proxy_details ) && array_***_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_***_exists ("username " ,$ proxy_details ) && array_***_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 );
414
443
// status code extraction
415
444
$ httpcode = curl_getinfo ($ http , CURLINFO_HTTP_CODE );
416
-
445
+
417
446
// close the curl
418
447
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 )) {
421
459
$ result = json_decode ($ response , true );
422
460
Utility::to_render_content ($ result , $ entry_uid , $ live_response_decode );
423
461
$ response = json_encode ($ result , true );
@@ -430,15 +468,19 @@ public static function contentstackRequest($queryObject = '', $type = '')
430
468
$ live_response_decode = json_decode ($ response , true );
431
469
432
470
}
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
+ }
437
477
}
438
478
}
479
+
439
480
return $ response ;
440
481
}
441
482
483
+
442
484
public static function to_render_content (&$ resp , $ entry_uid , $ live_response_decode ){
443
485
if (is_array ($ resp )) {
444
486
if (array_***_exists ('uid ' , $ resp ) && $ resp ['uid ' ] == $ entry_uid ){
@@ -452,6 +494,7 @@ public static function to_render_content(&$resp, $entry_uid, $live_response_deco
452
494
}
453
495
}
454
496
497
+
455
498
/**
456
499
* Validate the *** is set or not
457
500
*
0 commit comments