Replies: 1 comment 1 reply
-
@gpibarraI like your thoughts 👍 As I see it you are touching on two subjects: Sanitizing request/reponsesAs you mention it is often needed to sanitize the request (or response) for any confident data like authentication credentials. This can actually already be done in two different ways: Simply replace of stringsIt is possible to replace strings from the request/response by Providing on-demand configuration and using the undocumented configuration laravel-http-client-logger/src/HttpLogger.php Lines 50 to 53 in bc1eded Example: Http::log([], ['replace' => ['secret123456' => 'INTERCEPTED-APIKEY']])->get('https://example.com?apikey=secret123456'); Note that this does not work with Custom loggerIf you need a more advanced solution than the one above, going for a custom logger might be what you need. $logger = new CustomLogger('secret123456'); // This must implement HttpLoggerInterface but could be a class extending HttpLogger and implementing some advanced sanitize method
Http::log([], [], $logger)->get('https://example.com?apikey=secret123456'); Logging only request/responseIn some situations it might be relevant to only log responses in which case there is not really that much need for this package as you can do that without this package: $response = Http::get('https://example.com?apikey=secret123456');
\Log::debug(\GuzzleHttp\Psr7\Message::toString($response->toPsrResponse()) On the other hand only logging the requests might be relevant sometimes but I consider that more of a niche and hence I am reluctant to add configuration for that use case, especially since this can already be done using a custom logger I described above. Let me know if this can be used or not. |
Beta Was this translation helpful? Give feedback.
-
In configure file add boolean values for setting if save request and if save response. For example
In function "getMessage" and "logToDisk" check those values.
A possible need for this is when the request contains confidential data
Alternatively, after getting the data from psrMessageStringConverter, some interceptor can be implemented to sanitize confidential data.
Beta Was this translation helpful? Give feedback.
All reactions