Permalink
Browse files

FEATURE: added basic http authentication from dsn_part

  • Loading branch information...
1 parent fc6a13a commit 20196bf143a6c7287f60e764571056397698c29d @rpl rpl committed Dec 2, 2009
Showing with 9 additions and 0 deletions.
  1. +3 −0 examples/01_databases.php
  2. +6 −0 lib/couch.php
@@ -8,7 +8,10 @@
*/
+### ANON DSN
$couch_dsn = "http://localhost:5984/";
+### AUTHENTICATED DSN
+### $couch_dsn = "http://user:password@localhost:5984/"
$couch_db = "example";
View
@@ -293,6 +293,12 @@ protected function _socket_buildRequest($method,$url,$data) {
if ( is_object($data) OR is_array($data) )
$data = json_encode($data);
$req = "$method $url HTTP/1.0\r\nHost: ".$this->dsn_part('host')."\r\n";
+
+ if ( $this->dsn_part('user') && $this->dsn_part('pass') ) {
+ $req .= 'Authorization: Basic '.base64_encode($this->dsn_part('user').':'.
+ $this->dsn_part('pass'))."\r\n";
+ }
+
$req.= "Accept: application/json,text/html,text/plain,*/*\r\n";
if ( $method == 'COPY') {
$req .= 'Destination: '.$data."\r\n\r\n";

0 comments on commit 20196bf

Please sign in to comment.