66 * Namhyeon Go (Catswords Research) <[email protected] > 77 * https://github.com/gnh1201/caterpillar
88 * Created at: 2022-10-06
9- * Updated at: 2025-02-17
9+ * Updated at: 2025-03-11
1010 */
1111define ("PERF_START_TIME " , microtime (true ));
1212define ("PHP_HTTPPROXY_VERSION " , "0.1.6.10 " );
@@ -477,6 +477,34 @@ function relay_fetch_url($params) {
477477 $ headers = array_get ("headers " , $ params , array ());
478478 $ data = array_get ("data " , $ params , '' );
479479
480+ // from local source
481+ $ local_prefix = "file: " ;
482+ $ pos = strpos ($ url , $ local_prefix );
483+ if ($ pos !== false && $ pos == 0 ) {
484+ $ path = substr ($ url , strlen ($ local_prefix ));
485+
486+ if (file_exists ($ path )) {
487+ $ response = file_get_contents ($ path );
488+ return array (
489+ "success " => true ,
490+ "result " => array (
491+ "status " => 200 ,
492+ "data " => $ response
493+ )
494+ );
495+ } else {
496+ return array (
497+ "success " => false ,
498+ "error " => array (
499+ "status " => 404 ,
500+ "code " => -1 ,
501+ "message " => "Not found "
502+ )
503+ );
504+ }
505+ }
506+
507+ // from remote source
480508 $ _headers = array ();
481509 if (is_array ($ headers ) && count ($ headers ) > 0 ) {
482510 foreach ($ headers as $ header_line ) {
@@ -495,8 +523,10 @@ function relay_fetch_url($params) {
495523 curl_setopt ($ ch , CURLOPT_URL , $ url );
496524 curl_setopt ($ ch , CURLOPT_USERAGENT , DEFAULT_USER_AGENT );
497525 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
498- curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , 1 );
526+ curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , 30 );
499527 curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , false );
528+ curl_setopt ($ ch , CURLOPT_DNS_USE_GLOBAL_CACHE , false );
529+ curl_setopt ($ ch , CURLOPT_DNS_CACHE_TIMEOUT , 30 );
500530
501531 // check the request headers
502532 if (count ($ _headers ) > 0 ) {
@@ -585,14 +615,17 @@ function relay_invoke_method($params) {
585615 foreach ($ requires as $ require_ctx ) {
586616 $ resource_url = "" ;
587617 $ resource_integrity = "" ;
588-
589- if (is_array ($ require_ctx )) {
618+
619+ if (is_string ($ require_ctx )) {
620+ $ resource_url = $ require_ctx ;
621+ } else if (is_array ($ require_ctx )) {
590622 $ resource_url = array_get ("url " , $ require_ctx , "" );
591623 $ resource_integrity = array_get ("integrity " , $ require_ctx , "" );
592- } else {
593- $ resource_url = $ require_ctx ;
594624 }
595-
625+
626+ if (empty ($ resource_url ))
627+ continue ;
628+
596629 try {
597630 $ result = relay_fetch_url (array (
598631 "url " => $ resource_url
0 commit comments