Skip to content

Commit 5cc2d4c

Browse files
committed
Fix not display response body if option is false
1 parent f169f8c commit 5cc2d4c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ public function getLogContent(Request $request, Response $response, array $optio
7777

7878
// Render post parameters
7979
if (array_key_exists('post_parameters', $options)
80-
&& $options['post_parameters'] == true
80+
&& $options['post_parameters'] === true
8181
&& in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'])) {
8282
$responseContent .= "Post parameters\n";
8383
$responseContent .= $this->formatParameters($request->request->all());
8484
}
8585

8686
// Render response body content
87-
if (isset($options['response_body'])) {
87+
if (array_key_exists('response_body', $options)
88+
&& $options['response_body'] === true) {
8889
$responseContent .= "Response body\n------------------------\n";
8990
$responseContent .= $response->getContent()."\n";
9091
}

src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public function testProvider(): void
8383
->string($provider->getLogContent($request, $response, ['response_body' => true]))
8484
->contains("Response body\n")
8585
->contains($response->getContent())
86+
->string($provider->getLogContent($request, $response, ['response_body' => false]))
87+
->notContains("Response body\n")
88+
->notContains($response->getContent())
8689
->array($logContext = $provider->getLogContext($request, $response, []))
8790
->hasSize(7)
8891
->hasKeys(['environment', 'route', 'method', 'status', 'user', 'key', 'uri'])

0 commit comments

Comments
 (0)