@@ -375,10 +375,11 @@ 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
- $ server_output = '' ;
381
-
380
+ $ retryDelay = $ stack ->retryDelay ;
381
+ $ retryLimit = $ stack ->retryLimit ;
382
+ $ errorRetry = $ stack ->errorRetry ;
382
383
if ($ queryObject ) {
383
384
if (Utility::isLivePreview ($ queryObject )) {
384
385
$ queryObject ->_query ['live_preview ' ] = ($ queryObject ->contentType ->stack ->live_preview ['live_preview ' ] ?? 'init ' );
@@ -399,30 +400,67 @@ public static function contentstackRequest($queryObject = '', $type = '')
399
400
if ($ Headers ["branch " ] !== '' && $ Headers ["branch " ] !== "undefined " ) {
400
401
$ request_headers [] = 'branch: ' .$ Headers ["branch " ];
401
402
}
403
+
404
+ $ proxy_details = $ stack ->proxy ;
405
+ $ timeout = $ stack ->timeout ;
406
+
402
407
curl_setopt ($ http , CURLOPT_HTTPHEADER , $ request_headers );
403
408
404
409
curl_setopt ($ http , CURLOPT_HEADER , false );
405
410
// setting the GET request
406
411
curl_setopt ($ http , CURLOPT_CUSTOMREQUEST , "GET " );
407
412
// receive server response ...
408
413
curl_setopt ($ http , CURLOPT_RETURNTRANSFER , true );
409
- $ response = curl_exec ($ http );
414
+ // set the cURL time out
415
+ curl_setopt ($ http , CURLOPT_TIMEOUT_MS , $ timeout );
416
+
417
+ if (array_***_exists ("url " ,$ proxy_details ) && array_***_exists ("port " ,$ proxy_details )){
418
+ if ($ proxy_details ['url ' ] != '' && $ proxy_details ['port ' ] != '' ) {
410
419
420
+ // Set the proxy IP
421
+ curl_setopt ($ http , CURLOPT_PROXY , $ proxy_details ['url ' ]);
422
+ // Set the port
423
+ curl_setopt ($ http , CURLOPT_PROXYPORT , $ proxy_details ['port ' ]);
424
+
425
+ if (array_***_exists ("username " ,$ proxy_details ) && array_***_exists ("password " ,$ proxy_details )){
426
+ if ($ proxy_details ['username ' ] != '' && $ proxy_details ['password ' ] != '' ) {
427
+
428
+ $ proxyauth = $ proxy_details ['username ' ].": " .$ proxy_details ['password ' ];
429
+ // Set the username and password
430
+ curl_setopt ($ http , CURLOPT_PROXYUSERPWD , $ proxyauth );
431
+
432
+ }
433
+ }
434
+ }
435
+ }
436
+
437
+ $ response = curl_exec ($ http );
411
438
// status code extraction
412
439
$ httpcode = curl_getinfo ($ http , CURLINFO_HTTP_CODE );
413
-
440
+
414
441
// close the curl
415
442
curl_close ($ http );
416
- if ($ httpcode > 199 && $ httpcode < 300 ) {
417
- // wrapper the server result
418
- $ response = Utility::wrapResult ($ response , $ queryObject );
443
+ if (in_array ($ httpcode ,$ errorRetry )){
444
+ if ($ count < $ retryLimit ){
445
+ $ retryDelay = round ($ retryDelay /1000 ); //converting retry_delay from milliseconds into seconds
446
+ sleep ($ retryDelay ); //sleep method requires time in seconds
447
+ $ count += 1 ;
448
+ return Utility::contentstackRequest ($ stack , $ queryObject , $ type , $ count );
449
+ }
419
450
} else {
420
- throw new CSException ($ response , $ httpcode );
451
+ if ($ httpcode > 199 && $ httpcode < 300 ) {
452
+ // wrapper the server result
453
+ $ response = Utility::wrapResult ($ response , $ queryObject );
454
+ }
455
+ else {
456
+ throw new CSException ($ response , $ httpcode );
457
+ }
421
458
}
422
459
}
423
460
return $ response ;
424
461
}
425
462
463
+
426
464
/**
427
465
* Validate the *** is set or not
428
466
*
0 commit comments