Check for proxy configuration first, so we don't lose the Proxy-Authorization
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 28 Feb 2009 21:06:42 +0000 (16:06 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 28 Feb 2009 21:06:42 +0000 (16:06 -0500)
header.

Need to concatenate the header name with the value before we perform
the implode function on the array or we lose the header names.

framework/Http_Client/lib/Horde/Http/Client.php

index 64ca8ff..0ed4365 100644 (file)
@@ -209,15 +209,8 @@ class Horde_Http_Client
             'data' => $data,
         );
 
-        // Stream context config.
-        $opts = array('http' => array(
-            'method' => $method,
-            'header' => implode("\n", $headers),
-            'content' => $data,
-            'timeout' => $this->_timeout,
-        ));
-
-        // Proxy settings
+        $opts = array('http' => array());
+        // Proxy settings - check first, so we can include the correct headers
         if ($this->proxyServer) {
             $opts['http']['proxy'] = 'tcp://' . $this->proxyServer;
             $opts['http']['request_fulluri'] = true;
@@ -226,6 +219,18 @@ class Horde_Http_Client
             }
         }
 
+        // Concantenate the headers
+        $hdr = array();
+        foreach ($headers as $header => $value) {
+            $hdr[] = $header . ': ' . $value;
+        }
+
+        // Stream context config.
+        $opts['http']['method'] = $method;
+        $opts['http']['header'] = implode("\n", $hdr);
+        $opts['http']['content'] = $data;
+        $opts['http']['timeout'] = $this->_timeout;
+
         $context = stream_context_create($opts);
         $stream = @fopen($uri, 'rb', false, $context);
         if (!$stream) {