Skip to content

Commit ce355c8

Browse files
committed
:octocat: debug log HTTP messages in Client::sendRequest()
1 parent 163e813 commit ce355c8

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Psr18/CurlClient.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use chillerlan\HTTP\CurlUtils\CurlHandle;
1414
use Psr\Http\Message\{RequestInterface, ResponseInterface};
1515

16+
use function chillerlan\HTTP\Utils\message_to_string;
1617
use function curl_errno, curl_error, curl_exec, in_array;
1718

1819
use const CURLE_OK;
@@ -25,6 +26,8 @@ class CurlClient extends HTTPClientAbstract{
2526
* @inheritDoc
2627
*/
2728
public function sendRequest(RequestInterface $request):ResponseInterface{
29+
$this->logger->debug("\n----HTTP-REQUEST----\n".message_to_string($request));
30+
2831
$this->handle = $this->createHandle($request);
2932
$this->handle->init();
3033

@@ -47,10 +50,11 @@ public function sendRequest(RequestInterface $request):ResponseInterface{
4750
}
4851

4952
$this->handle->close();
50-
$r = $this->handle->getResponse();
51-
$r->getBody()->rewind();
53+
$response = $this->handle->getResponse();
54+
$this->logger->debug("\n----HTTP-RESPONSE---\n".message_to_string($response));
55+
$response->getBody()->rewind();
5256

53-
return $r;
57+
return $response;
5458
}
5559

5660
/**

src/Psr18/StreamClient.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use ErrorException, Exception;
1616
use Psr\Http\Message\{RequestInterface, ResponseInterface};
1717

18+
use function chillerlan\HTTP\Utils\message_to_string;
1819
use function explode, file_get_contents, get_headers, in_array, intval, restore_error_handler,
1920
set_error_handler, stream_context_create, strtolower, substr, trim;
2021

@@ -26,6 +27,8 @@ class StreamClient extends HTTPClientAbstract{
2627
*
2728
*/
2829
public function sendRequest(RequestInterface $request):ResponseInterface{
30+
$this->logger->debug("\n----HTTP-REQUEST----\n".message_to_string($request));
31+
2932
$uri = $request->getUri();
3033
$method = $request->getMethod();
3134
$headers = $this->getRequestHeaders($request);
@@ -80,6 +83,7 @@ public function sendRequest(RequestInterface $request):ResponseInterface{
8083
;
8184

8285
$response->getBody()->write($responseBody);
86+
$this->logger->debug("\n----HTTP-RESPONSE---\n".message_to_string($response));
8387
$response->getBody()->rewind();
8488

8589
return $response;

0 commit comments

Comments
 (0)