From 01e89e36526724df3efa98350a64654e4e9f14ad Mon Sep 17 00:00:00 2001 From: droletmarc Date: Fri, 14 Jul 2017 08:24:01 -0400 Subject: [PATCH 1/4] - I've added code to remove the temporary session file that get create on each rets request. This file is not used anymore once we get the gets server response and it didn't get removed. - /tmp folder was hardcoded, I've added a way to configure it into the configuration of the PHRets. By default it will be null. --- src/Configuration.php | 19 +++++++++++++++++++ src/Session.php | 21 +++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Configuration.php b/src/Configuration.php index d2e9bb9..0657ba9 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -20,6 +20,7 @@ class Configuration protected $http_authentication = 'digest'; /** @var \PHRETS\Strategies\Strategy */ protected $strategy; + protected $sessionTempDir = null; protected $options = []; public function __construct() @@ -135,6 +136,24 @@ public function setUsername($username) return $this; } + /** + * @param string $username + * @return $this + */ + public function setSessionTempDir($sessionTempDir) + { + $this->sessionTempdDir = $sessionTempDir; + return $this; + } + + /** + * @return mixed + */ + public function getSessionTempDir() + { + return $this->sessionTempDir; + } + /** * @param $name * @param $value diff --git a/src/Session.php b/src/Session.php index 63ba0a5..e85aea2 100644 --- a/src/Session.php +++ b/src/Session.php @@ -339,6 +339,8 @@ protected function request($capability, $options = []) $response = new \PHRETS\Http\Response($response); + $this->removeSessionCookieFile($options); + $this->last_response = $response; if ($response->getHeader('Set-Cookie')) { @@ -349,7 +351,7 @@ protected function request($capability, $options = []) } } } - + if (preg_match('/text\/xml/', $response->getHeader('Content-Type')) and $capability != 'GetObject') { $parser = $this->grab(Strategy::PARSER_XML); $xml = $parser->parse($response); @@ -481,7 +483,7 @@ public function getDefaultOptions() 'Accept-Encoding' => 'gzip', 'Accept' => '*/*', ], - 'curl' => [ CURLOPT_COOKIEFILE => tempnam('/tmp', 'phrets') ] + 'curl' => [ CURLOPT_COOKIEFILE => tempnam($this->configuration->getSessionTempDir(), 'phrets') ] ]; // disable following 'Location' header (redirects) automatically @@ -492,6 +494,21 @@ public function getDefaultOptions() return $defaults; } + /** + * If the session cookie file have beend created, we will remove it. + * + * @param array $options Assoc array that came from the method getDefaultOptions. + * + * @return void + */ + private function removeSessionCookieFile(array $options) + { + $tmpFile = $options['curl'][CURLOPT_COOKIEFILE]; + if (file_exists($tmpFile)) { + unlink($tmpFile); + } + } + public function setParser($parser_name, $parser_object) { /** @var Container $container */ From aaf595c993d05702e8a91283a06678b314fe1286 Mon Sep 17 00:00:00 2001 From: droletmarc Date: Thu, 3 Aug 2017 10:37:06 -0400 Subject: [PATCH 2/4] Some rets service, like the one from bridge-rets.mlspin.com do not work if you pass a value (basic or digest) into the http_authentication. I've modify the code to be able to pass http_authentication = null when we set the config. --- src/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Configuration.php b/src/Configuration.php index 0657ba9..f222489 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -259,7 +259,7 @@ public function userAgentDigestHash(Session $session) */ public function setHttpAuthenticationMethod($auth_method) { - if (!in_array($auth_method, [self::AUTH_BASIC, self::AUTH_DIGEST])) { + if ($auth_method && !in_array($auth_method, [self::AUTH_BASIC, self::AUTH_DIGEST])) { throw new \InvalidArgumentException("Given authentication method is invalid. Must be 'basic' or 'digest'"); } $this->http_authentication = $auth_method; From 788d1ec8147ac88a81fbbe437e583357b27bf208 Mon Sep 17 00:00:00 2001 From: droletmarc Date: Thu, 3 Aug 2017 10:43:28 -0400 Subject: [PATCH 3/4] revert --- src/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Configuration.php b/src/Configuration.php index f222489..0657ba9 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -259,7 +259,7 @@ public function userAgentDigestHash(Session $session) */ public function setHttpAuthenticationMethod($auth_method) { - if ($auth_method && !in_array($auth_method, [self::AUTH_BASIC, self::AUTH_DIGEST])) { + if (!in_array($auth_method, [self::AUTH_BASIC, self::AUTH_DIGEST])) { throw new \InvalidArgumentException("Given authentication method is invalid. Must be 'basic' or 'digest'"); } $this->http_authentication = $auth_method; From 543a7980437cfeef79c813f8d98b2eb70ae9a084 Mon Sep 17 00:00:00 2001 From: droletmarc Date: Thu, 3 Aug 2017 10:44:06 -0400 Subject: [PATCH 4/4] Some rets service, like the one from bridge-rets.mlspin.com do not work if you pass a value (basic or digest) into the http_authentication. I've modify the code to be able to pass http_authentication = null when we set the config. --- src/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Configuration.php b/src/Configuration.php index 0657ba9..f222489 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -259,7 +259,7 @@ public function userAgentDigestHash(Session $session) */ public function setHttpAuthenticationMethod($auth_method) { - if (!in_array($auth_method, [self::AUTH_BASIC, self::AUTH_DIGEST])) { + if ($auth_method && !in_array($auth_method, [self::AUTH_BASIC, self::AUTH_DIGEST])) { throw new \InvalidArgumentException("Given authentication method is invalid. Must be 'basic' or 'digest'"); } $this->http_authentication = $auth_method;