From 3bf1336af718aed40279d27abd9ef7ec36303f95 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 6 Jun 2019 11:21:24 +0000 Subject: [PATCH] httpclient : add the authentication method and do not reset it between connections git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5319 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- httpclient.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/httpclient.php b/httpclient.php index 4f2d350..ba334ec 100644 --- a/httpclient.php +++ b/httpclient.php @@ -55,6 +55,10 @@ class Httpclient */ private $ssloptions = array (); + /** Authentication value + */ + private $authentication = ""; + /** The maximum maxsize allowed */ private $maxsize; @@ -436,8 +440,22 @@ class Httpclient public function authBasic ($login, $password) // {{{ { - $this->headersSent["Authorization"] = "Basic ". - base64_encode ("$login:$password"); + $this->authentication = "Basic ". base64_encode ("$login:$password"); + return $this; + } + // }}} + + /** Get/Set authentication + * To remove authentication, pass "" to $auth arg + * @param string|null $auth The authentication string to send + * @return value or $this + */ + public function authentication ($auth = null) + // {{{ + { + if ($auth === null) + return $this->authentication; + $this->authentication = $auth; return $this; } // }}} @@ -568,6 +586,8 @@ class Httpclient $this->headersSent["User-Agent"] = $this->useragent; if ($this->referer !== "") $this->headersSent["Referer"] = $this->referer; + if ($this->authentication !== "") + $this->headersSent["Authorization"] = $this->authentication; $this->headersSent["Connection"] = "keep-alive"; $cookies = $this->cookieToSend ($this->url); if (! empty ($cookies))