From 06619eb763ffcbeb7c2fbf806bca2149479674a9 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 31 Aug 2009 05:56:54 +0000 Subject: - Patch #553276 by boombatower: added HTTP authentication support to the (simpletest) browser. --- includes/browser.inc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'includes/browser.inc') diff --git a/includes/browser.inc b/includes/browser.inc index a6c4219d2..9b1a22922 100644 --- a/includes/browser.inc +++ b/includes/browser.inc @@ -206,6 +206,31 @@ class Browser { $this->requestHeaders['User-Agent'] = $agent; } + /** + * Get HTTP authentication information. + * + * @return + * Authentication information in the format, username:password. + */ + public function getHttpAuthentication() { + if (isset($this->requestHeaders['Authorization'])) { + return base64_decode($this->requestHeaders['Authorization']); + } + return NULL; + } + + /** + * Set HTTP authentication information. + * + * @param $username + * HTTP authentication username, which cannot contain a ":". + * @param $password + * HTTP authentication password. + */ + public function setHttpAuthentication($username, $password) { + $this->requestHeaders['Authorization'] = base64_encode("$username:$password"); + } + /** * Get the URL of the current page. * @@ -660,6 +685,9 @@ class Browser { $this->headers = array(); // Ensure that request headers are up to date. + if ($this->getHttpAuthentication()) { + curl_setopt($this->handle, CURLOPT_USERPWD, $this->getHttpAuthentication()); + } curl_setopt($this->handle, CURLOPT_USERAGENT, $this->requestHeaders['User-Agent']); curl_setopt($this->handle, CURLOPT_HTTPHEADER, $this->requestHeaders); -- cgit v1.2.3