Skip to content

Commit

Permalink
Added foce_http_version_10 option
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech authored and dantleech committed Apr 1, 2015
1 parent 186ab65 commit 403a8ef
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Jackalope/RepositoryFactoryJackrabbit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);

/**
Expand Down Expand Up @@ -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']));
}
Expand Down
27 changes: 22 additions & 5 deletions src/Jackalope/Transport/Jackrabbit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -295,6 +308,10 @@ protected function getRequest($method, $uri, $addWorkspacePathToUri = true)
$request->addHeader("Expect:");
}

if ($this->forceHttpVersion10) {
$request->forceHttpVersion10();
}

return $request;
}

Expand Down
25 changes: 25 additions & 0 deletions src/Jackalope/Transport/Jackrabbit/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
Expand Down Expand Up @@ -463,13 +477,18 @@ 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) {
$curl->parseResponseHeaders();
}

$response = $curl->exec();

$curl->setResponse($response);

$httpCode = $curl->getinfo(CURLINFO_HTTP_CODE);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 403a8ef

Please sign in to comment.