Skip to content

Commit f1eddcf

Browse files
committed
message accessor cannot be configured with ad-hoc configuration, throw exception if this is attempt; docs + test improvements
1 parent 0ad6d9e commit f1eddcf

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

config/http-client-logger.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
|
5454
| These settings determine what data should be replaced with a placeholder.
5555
|
56-
| - replace contains an array of strings that will be replaced anywhere in the request/response
56+
| - replace contains an associative array of strings, where the key will be replaced with the value everywhere in the request/response
5757
| - replace_values will be replaced in headers, query parameters and json data (but not json keys)
5858
| - replace_headers contains an array of header names whose values are replaced with placeholders
5959
| - replace_query contains an array of query parameter names whose values are replaced with placeholders

src/HttpLogger.php

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ public function log(
3737
$this->response = $response;
3838
$this->sec = $sec;
3939
$this->context = $context;
40+
41+
// ad-hoc config is not supported for message accessor settings: replace_json, replace_query, replace_headers, replace_values.
42+
if (Arr::hasAny($config, ['replace_json', 'replace_query', 'replace_headers', 'replace_values'])) {
43+
throw new \InvalidArgumentException('Ad-hoc config does not support replace_json, replace_query, replace_headers, replace_values.');
44+
}
45+
4046
$this->config = array_merge(config('http-client-logger'), $config);
4147

4248
if (Arr::get($this->config, 'channel')) {

tests/PsrMessageToStringConverterTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public function test_to_string_replaces_sensitive_data()
6161
'sensitive data not replaced in URI'
6262
);
6363

64+
$this->assertStringNotContainsString(
65+
'123456',
66+
$string,
67+
'sensitive data not replaced in json'
68+
);
69+
6470
$this->assertStringContainsString(
6571
'Host: ********.example.com:9000',
6672
$string,

0 commit comments

Comments
 (0)