summaryrefslogtreecommitdiff
path: root/includes/browser.inc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-08-31 05:56:54 +0000
committerDries Buytaert <dries@buytaert.net>2009-08-31 05:56:54 +0000
commit06619eb763ffcbeb7c2fbf806bca2149479674a9 (patch)
treee4a7e9d430220702a0152987b4bb6d7cf5e4339c /includes/browser.inc
parente6e29ac1b0d6780241ced3d5ebcb0558e219e468 (diff)
downloadbrdo-06619eb763ffcbeb7c2fbf806bca2149479674a9.tar.gz
brdo-06619eb763ffcbeb7c2fbf806bca2149479674a9.tar.bz2
- Patch #553276 by boombatower: added HTTP authentication support to the (simpletest) browser.
Diffstat (limited to 'includes/browser.inc')
-rw-r--r--includes/browser.inc28
1 files changed, 28 insertions, 0 deletions
diff --git a/includes/browser.inc b/includes/browser.inc
index a6c4219d2..9b1a22922 100644
--- a/includes/browser.inc
+++ b/includes/browser.inc
@@ -207,6 +207,31 @@ class Browser {
}
/**
+ * 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.
*
* @return
@@ -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);