@@ -97,8 +97,8 @@ public function handleRequestResponse(
9797 'headers ' => $ request ->getHeaders ()->toString (),
9898 'routeMatch ' => $ routeMatch ? $ routeMatch ->getMatchedRouteName () : '' ,
9999 'url ' => $ request ->getUriString (),
100- 'body ' => $ request ->getContent (),
101- 'query ' => $ request ->getQuery ()->toString (),
100+ 'body ' => $ this -> blurKeywords ( $ request ->getContent () ),
101+ 'query ' => $ this -> blurKeywords ( $ request ->getQuery ()->toString () ),
102102 'method ' => $ request ->getMethod (),
103103 ],
104104 'response ' => [
@@ -127,6 +127,40 @@ public function getAdapters(): array
127127 return $ this ->adapters ;
128128 }
129129
130+ /**
131+ * Check if string contains keys that should be blurred out
132+ * This will only check top-level
133+ *
134+ * @param string $body
135+ * @return string
136+ */
137+ private function blurKeywords (string $ body ): string
138+ {
139+ try {
140+ $ isJson = true ;
141+ $ bodyAsArray = Json::decode ($ body , true );
142+ } catch (RuntimeException $ e ) {
143+ $ isJson = false ;
144+ parse_str ($ body , $ bodyAsArray );
145+ }
146+
147+ if (!is_array ($ bodyAsArray )) {
148+ return $ body ;
149+ }
150+
151+ foreach ($ bodyAsArray as $ key => $ value ) {
152+ if (in_array ($ key , $ this ->options ->getBlurredKeys (), false )) {
153+ $ bodyAsArray [$ key ] = $ this ->options ->getBlurredKeysValue ();
154+ }
155+ }
156+
157+ if ($ isJson ) {
158+ return Json::encode ($ bodyAsArray );
159+ }
160+
161+ return http_build_query ($ bodyAsArray );
162+ }
163+
130164 /**
131165 * Check if matched route should always be logged for http request/response
132166 *
0 commit comments