1212namespace FOS \HttpCache \ProxyClient ;
1313
1414use FOS \HttpCache \Exception \ExceptionCollection ;
15+ use FOS \HttpCache \Exception \ProxyResponseException ;
1516use FOS \HttpCache \Exception \ProxyUnreachableException ;
1617use FOS \HttpCache \ProxyClient \Request \InvalidationRequest ;
1718use FOS \HttpCache \ProxyClient \Request \RequestQueue ;
18- use Ivory \ HttpAdapter \ HttpAdapterFactory ;
19- use Ivory \ HttpAdapter \ HttpAdapterInterface ;
20- use Ivory \ HttpAdapter \ MultiHttpAdapterException ;
19+ use Http \ Adapter \ Exception \ MultiHttpAdapterException ;
20+ use Http \ Adapter \ Guzzle6HttpAdapter ;
21+ use Http \ Adapter \ PsrHttpAdapter ;
2122
2223/**
2324 * Abstract caching proxy client
@@ -29,7 +30,7 @@ abstract class AbstractProxyClient implements ProxyClientInterface
2930 /**
3031 * HTTP client
3132 *
32- * @var HttpAdapterInterface
33+ * @var PsrHttpAdapter
3334 */
3435 private $ httpAdapter ;
3536
@@ -51,15 +52,15 @@ abstract class AbstractProxyClient implements ProxyClientInterface
5152 * requests (optional). This is required if
5253 * you purge and refresh paths instead of
5354 * absolute URLs.
54- * @param HttpAdapterInterface $httpAdapter If no HTTP client is supplied, a
55+ * @param PsrHttpAdapter $httpAdapter If no HTTP adapter is supplied, a
5556 * default one will be created.
5657 */
5758 public function __construct (
5859 array $ servers ,
5960 $ baseUrl = null ,
60- HttpAdapterInterface $ httpAdapter = null
61+ PsrHttpAdapter $ httpAdapter = null
6162 ) {
62- $ this ->httpAdapter = $ httpAdapter ?: HttpAdapterFactory:: guess ();
63+ $ this ->httpAdapter = $ httpAdapter ?: new Guzzle6HttpAdapter ();
6364 $ this ->initQueue ($ servers , $ baseUrl );
6465 }
6566
@@ -80,20 +81,24 @@ public function flush()
8081 } catch (MultiHttpAdapterException $ e ) {
8182 $ collection = new ExceptionCollection ();
8283 foreach ($ e ->getExceptions () as $ exception ) {
83- $ collection ->add (
84- ProxyUnreachableException::proxyUnreachable (
85- $ exception ->getRequest ()->getHeader ('Host ' ),
86- $ exception ->getMessage (),
87- null ,
88- $ exception
89- )
90- );
84+ // A workaround for php-http currently lacking differentiation
85+ // between client, server and networking errors.
86+ if (!$ exception ->getResponse ()) {
87+ // Assume networking error if no response was returned.
88+ $ collection ->add (
89+ ProxyUnreachableException::proxyUnreachable ($ exception )
90+ );
91+ } else {
92+ $ collection ->add (
93+ ProxyResponseException::proxyResponse ($ exception )
94+ );
95+ }
9196 }
9297
9398 throw $ collection ;
9499 }
95100
96- return count ($ responses );
101+ return count ($ queue );
97102 }
98103
99104 protected function queueRequest ($ method , $ url , array $ headers = array ())
0 commit comments