From 403a8efd8c7a25d308e2c1b590b9d856d1cfc144 Mon Sep 17 00:00:00 2001 From: dantleech Date: Fri, 27 Mar 2015 10:01:33 +0000 Subject: [PATCH] Added foce_http_version_10 option --- src/Jackalope/RepositoryFactoryJackrabbit.php | 4 +++ src/Jackalope/Transport/Jackrabbit/Client.php | 27 +++++++++++++++---- .../Transport/Jackrabbit/Request.php | 25 +++++++++++++++++ 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/Jackalope/RepositoryFactoryJackrabbit.php b/src/Jackalope/RepositoryFactoryJackrabbit.php index 8cf76ae4..711a6fcd 100644 --- a/src/Jackalope/RepositoryFactoryJackrabbit.php +++ b/src/Jackalope/RepositoryFactoryJackrabbit.php @@ -42,6 +42,7 @@ class RepositoryFactoryJackrabbit implements RepositoryFactoryInterface 'jackalope.disable_stream_wrapper' => 'boolean: if set and not empty, stream wrapper is disabled, otherwise the stream wrapper is enabled and streams are only fetched when reading from for the first time. If your code always uses all binary properties it reads, you can disable this for a small performance gain.', 'jackalope.logger' => 'Psr\Log\LoggerInterface: Use the LoggingClient to wrap the default transport Client', Session::OPTION_AUTO_LASTMODIFIED => 'boolean: Whether to automatically update nodes having mix:lastModified. Defaults to true.', + 'jackalope.jackrabbit_force_http_version_10' => 'boolean: Force HTTP version 1.0, this can in solving problems with curl such as https://github.com/jackalope/jackalope-jackrabbit/issues/89', ); /** @@ -93,6 +94,9 @@ public function getRepository(array $parameters = null) if (isset($parameters['jackalope.check_login_on_server'])) { $transport->setCheckLoginOnServer($parameters['jackalope.check_login_on_server']); } + if (isset($parameters['jackalope.jackrabbit_force_http_version_10'])) { + $transport->forceHttpVersion10($parameters['jackalope.jackrabbit_force_http_version_10']); + } if (isset($parameters['jackalope.logger'])) { $transport = $factory->get('Transport\Jackrabbit\LoggingClient', array($transport, $parameters['jackalope.logger'])); } diff --git a/src/Jackalope/Transport/Jackrabbit/Client.php b/src/Jackalope/Transport/Jackrabbit/Client.php index 08ced390..a3e9dc70 100644 --- a/src/Jackalope/Transport/Jackrabbit/Client.php +++ b/src/Jackalope/Transport/Jackrabbit/Client.php @@ -166,18 +166,21 @@ class Client extends BaseTransport implements QueryTransport, PermissionInterfac protected $curl = null; /** - * A list of additional HTTP headers to be sent on each request - * @var array[]string + * A list of additional HTTP headers to be sent on each request + * @var array[]string */ - protected $defaultHeaders = array(); /** - * @var bool Send Expect: 100-continue header + * @var bool Send Expect: 100-continue header */ - protected $sendExpect = false; + /** + * @var bool + */ + protected $forceHttpVersion10 = false; + /** * @var \Jackalope\NodeType\NodeTypeXmlConverter */ @@ -265,6 +268,16 @@ public function sendExpect($send = true) $this->sendExpect = $send; } + /** + * Set to true to force HTTP version 1.0 + * + * @param boolean + */ + public function forceHttpVersion10($forceHttpVersion10 = true) + { + $this->forceHttpVersion10 = $forceHttpVersion10; + } + /** * Makes sure there is an open curl connection. * @@ -295,6 +308,10 @@ protected function getRequest($method, $uri, $addWorkspacePathToUri = true) $request->addHeader("Expect:"); } + if ($this->forceHttpVersion10) { + $request->forceHttpVersion10(); + } + return $request; } diff --git a/src/Jackalope/Transport/Jackrabbit/Request.php b/src/Jackalope/Transport/Jackrabbit/Request.php index 4bfaee60..caba77f5 100644 --- a/src/Jackalope/Transport/Jackrabbit/Request.php +++ b/src/Jackalope/Transport/Jackrabbit/Request.php @@ -211,6 +211,12 @@ class Request */ protected $errorHandlingMode = false; + /** + * Force curl to use HTTP version 1.0 + * @var bool + */ + protected $forceHttpVersion10 = false; + /** * Initiaties the NodeTypes request object. * @@ -229,6 +235,14 @@ public function __construct(FactoryInterface $factory, Client $client, curl $cur $this->setUri($uri); } + /** + * Force curl to use HTTP version 1.0 + */ + public function forceHttpVersion10() + { + $this->forceHttpVersion10 = true; + } + /** * Set the credentials for the request. Setting them to null will make a * request without authentication header. @@ -463,6 +477,10 @@ protected function singleRequest($getCurlObject) $curl->setopt(CURLOPT_URL, reset($this->uri)); $curl->setopt(CURLOPT_HTTPHEADER, $headers); $curl->setopt(CURLOPT_POSTFIELDS, $this->body); + + if (true === $this->forceHttpVersion10) { + $curl->setopt(CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); + } // uncomment next line to get verbose information from CURL //$curl->setopt(CURLOPT_VERBOSE, 1); if ($getCurlObject) { @@ -470,6 +488,7 @@ protected function singleRequest($getCurlObject) } $response = $curl->exec(); + $curl->setResponse($response); $httpCode = $curl->getinfo(CURLINFO_HTTP_CODE); @@ -520,6 +539,12 @@ protected function handleError(curl $curl, $response, $httpCode) case CURLE_COULDNT_CONNECT: $info = $curl->getinfo(); throw new NoSuchWorkspaceException($curl->error() . ' "' . $info['url'] . '"'); + case CURLE_RECV_ERROR: + throw new RepositoryException(sprintf( + 'CURLE_RECV_ERROR (errno 56) encountered. This has been known to happen intermittently with ' . + 'some versions of libcurl (see https://github.com/jackalope/jackalope-jackrabbit/issues/89). ' . + 'You can use the "jackalope.jackrabbit_force_http_version_10" option to force HTTP 1.0 as a workaround' + )); } // use XML error response if it's there