@@ -387,23 +387,6 @@ protected static function sendRequest($url, $options)
387
387
{
388
388
list ($ url , $ options ) = self ::buildHeaders ($ url , $ options );
389
389
390
- // check is the env variable is set
391
- if (getenv ('ECHO_OGC_ORIGINAL_REQUEST ' )) {
392
- // did the request has to be echoed ?
393
- if (self ::hasEchoInBody ($ options ['body ' ])) {
394
- $ content = self ::getEchoFromRequest ($ url , $ options ['body ' ]);
395
-
396
- // We do not perform the request, but return the content previously logged
397
- return new Response (
398
- 200 ,
399
- array ('Content-Type ' => 'text/json ' ),
400
- $ content ,
401
- );
402
- }
403
- // All requests are logged
404
- self ::logRequestToEcho ($ url , $ options ['body ' ]);
405
- }
406
-
407
390
if ($ options ['referer ' ]) {
408
391
$ options ['headers ' ]['Referer ' ] = $ options ['referer ' ];
409
392
}
@@ -420,6 +403,10 @@ protected static function sendRequest($url, $options)
420
403
$ stack = HandlerStack::create ();
421
404
$ stack ->push (new CacheMiddleware ($ strategy ));
422
405
406
+ // check is the env variable is set
407
+ if (getenv ('ECHO_OGC_ORIGINAL_REQUEST ' )) {
408
+ $ stack ->push (new EchoMiddleWare ());
409
+ }
423
410
// Create Client
424
411
$ client = new Client (array (
425
412
// You can set any number of default request options.
@@ -902,63 +889,6 @@ public static function clearLayerCache($repository, $project, $layer)
902
889
903
890
return true ;
904
891
}
905
-
906
- /**
907
- * check if $body contains a '__echo__=&' param.
908
- *
909
- * @return bool
910
- */
911
- public static function hasEchoInBody (string $ body )
912
- {
913
- $ encodedEchoParam = '%5F%5Fecho%5F%5F=& ' ;
914
-
915
- return strstr ($ body , $ encodedEchoParam );
916
- }
917
-
918
- /**
919
- * Log the URL and its body in the 'echoproxy' log file
920
- * We add a md5 hash of the string to help retrieving it later
921
- * NOTE : currently we log only the url & body, thus it doesn't really need to be logged
922
- * because the same url & body are needed to retreive the content
923
- * but the function will be useful when it will log additionnal content.
924
- */
925
- public static function logRequestToEcho (string $ url , string $ body )
926
- {
927
- $ md5 = md5 ($ url .'| ' .$ body );
928
- \jLog::log ($ md5 ."\t" .$ url .'? ' .$ body , 'echoproxy ' );
929
- }
930
-
931
- /**
932
- * return the content that was logged for the (url, body) params
933
- * using a md5 hash to search it in the log file.
934
- *
935
- * @see logRequestToEcho()
936
- */
937
- public static function getEchoFromRequest (string $ url , string $ body ): string
938
- {
939
- $ encodedEchoParam = '%5F%5Fecho%5F%5F=& ' ;
940
- // md5 hash to search in the file
941
- $ md5ToSearch = md5 ($ url .'| ' .str_replace ($ encodedEchoParam , '' , $ body ));
942
-
943
- $ logPath = \jApp::logPath ('echoproxy.log ' );
944
- if (is_file ($ logPath )) {
945
- // retrieve the 50 last lines
946
- $ nLastLines = preg_split ("/ \r\n| \n| \r/ " , App \FileTools::tail ($ logPath , 50 ));
947
- // key : md5 , value : usefull content
948
- $ md5Assoc = array ();
949
- foreach ($ nLastLines as $ line ) {
950
- $ words = explode ("\t" , $ line );
951
- if (count ($ words ) > 4
952
- && $ md5ToSearch == $ words [3 ]) {
953
- return $ words [4 ];
954
- }
955
- }
956
-
957
- return 'unfound ' .$ md5ToSearch ;
958
- }
959
-
960
- return 'unfound echoproxy.log ' ;
961
- }
962
892
}
963
893
964
894
/*
0 commit comments