1010use Http \Discovery \MessageFactoryDiscovery ;
1111use Http \Message \ResponseFactory ;
1212use Psr \Http \Message \RequestInterface ;
13+ use Throwable ;
1314
1415/**
1516 * Client compatible with PSR7 and Httplug interfaces, using a CakePHP client.
1617 */
1718class Client implements HttpClient
1819{
19- /** @var CakeClient */
20+ /**
21+ * @var CakeClient
22+ */
2023 private $ client ;
2124
22- /** @var ResponseFactory */
25+ /**
26+ * @var ResponseFactory
27+ */
2328 private $ responseFactory ;
2429
2530 /**
26- * @param CakeClient $client
27- * @param ResponseFactory $responseFactory
31+ * @param CakeClient|null $client
32+ * @param ResponseFactory|null $responseFactory
2833 */
2934 public function __construct (CakeClient $ client = null , ResponseFactory $ responseFactory = null )
3035 {
@@ -47,13 +52,13 @@ public function sendRequest(RequestInterface $request)
4752 ->withProtocolVersion ($ request ->getProtocolVersion ())
4853 ->withBody ($ request ->getBody ());
4954
50- if (null === $ cakeRequest ->header ('Content-Type ' )) {
51- $ cakeRequest-> header ('Content-Type ' , 'application/x-www-form-urlencoded ' );
55+ if (null === $ cakeRequest ->getHeader ('Content-Type ' )) {
56+ $ cakeRequest = $ cakeRequest -> withHeader ('Content-Type ' , 'application/x-www-form-urlencoded ' );
5257 }
5358
5459 try {
55- $ response = $ this ->client ->send ($ cakeRequest , $ this ->client ->config ());
56- } catch (Exception $ exception ) {
60+ $ response = $ this ->client ->send ($ cakeRequest , $ this ->client ->getConfig ());
61+ } catch (Throwable $ exception ) {
5762 throw new NetworkException ('Failed to send request ' , $ request , $ exception );
5863 }
5964
0 commit comments