Преглед на файлове

Add support for HTTP basic access authentication.

With Webdis it is possible to define some access control rules to allow or
disallow certain commands and one of the possible configurations is based on
plain old HTTP authentication.
Daniele Alessandri преди 13 години
родител
ревизия
e5a85dfce8
променени са 1 файла, в които са добавени 13 реда и са изтрити 1 реда
  1. 13 1
      lib/Predis/Network/WebdisConnection.php

+ 13 - 1
lib/Predis/Network/WebdisConnection.php

@@ -118,11 +118,23 @@ class WebdisConnection implements IConnectionSingle {
         }
     }
 
+    protected function getHttpOptions() {
+        $options = null;
+        if (isset($this->_parameters->user, $this->_parameters->pass)) {
+            $parameters = $this->_parameters;
+            $options = array(
+                'httpauth' => "{$parameters->user}:{$parameters->pass}",
+                'httpauthtype' => HTTP_AUTH_BASIC,
+            );
+        }
+        return $options;
+    }
+
     public function executeCommand(ICommand $command) {
         $commandId = $this->getCommandId($command);
         $arguments = implode('/', array_map('urlencode', $command->getArguments()));
 
-        $request = new HttpRequest($this->_webdisUrl, HttpRequest::METH_POST);
+        $request = new HttpRequest($this->_webdisUrl, HttpRequest::METH_POST, $this->getHttpOptions());
         $request->setBody("$commandId/$arguments.raw");
         $request->send();