예제 #1
0
파일: Client.php 프로젝트: dalinhuang/popo
 /**
  * Get the URI for the next request
  *
  * @param boolean $as_string If true, will return the URI as a string
  * @return Zend_Uri_Http|string
  */
 public function getUri($as_string = false)
 {
     if ($as_string && $this->uri instanceof Zend_Uri_Http) {
         return $this->uri->__toString();
     } else {
         return $this->uri;
     }
 }
 /**
  * Send request to the proxy server with streaming support
  *
  * @param string        $method
  * @param Zend_Uri_Http $uri
  * @param string        $http_ver
  * @param array         $headers
  * @param string        $body
  * @return string Request as string
  */
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     // If no proxy is set, throw an error
     if (!$this->config['proxy_host']) {
         // require_once 'Zend/Http/Client/Adapter/Exception.php';
         throw new Zend_Http_Client_Adapter_Exception('No proxy host set!');
     }
     // Make sure we're properly connected
     if (!$this->socket) {
         // require_once 'Zend/Http/Client/Adapter/Exception.php';
         throw new Zend_Http_Client_Adapter_Exception('Trying to write but we are not connected');
     }
     $host = $this->config['proxy_host'];
     $port = $this->config['proxy_port'];
     if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) {
         // require_once 'Zend/Http/Client/Adapter/Exception.php';
         throw new Zend_Http_Client_Adapter_Exception('Trying to write but we are connected to the wrong proxy ' . 'server');
     }
     // Add Proxy-Authorization header
     if ($this->config['proxy_user'] && !isset($headers['proxy-authorization'])) {
         $headers['proxy-authorization'] = Zend_Http_Client::encodeAuthHeader($this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']);
     }
     // if we are proxying HTTPS, preform CONNECT handshake with the proxy
     if ($uri->getScheme() == 'https' && !$this->negotiated) {
         $this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers);
         $this->negotiated = true;
     }
     // Save request method for later
     $this->method = $method;
     // Build request headers
     $request = "{$method} {$uri->__toString()} HTTP/{$http_ver}\r\n";
     // Add all headers to the request string
     foreach ($headers as $k => $v) {
         if (is_string($k)) {
             $v = "{$k}: {$v}";
         }
         $request .= "{$v}\r\n";
     }
     $request .= "\r\n";
     // Send the request headers
     if (!@fwrite($this->socket, $request)) {
         // require_once 'Zend/Http/Client/Adapter/Exception.php';
         throw new Zend_Http_Client_Adapter_Exception('Error writing request to proxy server');
     }
     // Read from $body, write to socket
     $chunk = $body->read(self::CHUNK_SIZE);
     while ($chunk !== false) {
         if (!@fwrite($this->socket, $chunk)) {
             // require_once 'Zend/Http/Client/Adapter/Exception.php';
             throw new Zend_Http_Client_Adapter_Exception('Error writing request to server');
         }
         $chunk = $body->read(self::CHUNK_SIZE);
     }
     $body->closeFileHandle();
     return 'Large upload, request is not cached.';
 }
예제 #3
0
 /**
  * Send request to the remote server
  *
  * @param  string        $method
  * @param  Zend_Uri_Http $uri
  * @param  float         $http_ver
  * @param  array         $headers
  * @param  string        $body
  * @return string        $request
  * @throws Zend_Http_Client_Adapter_Exception If connection fails, connected to wrong host, no PUT file defined, unsupported method, or unsupported cURL option
  */
 public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $body = '')
 {
     // Make sure we're properly connected
     if (!$this->_curl) {
         require_once 'Zend/Http/Client/Adapter/Exception.php';
         throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are not connected");
     }
     if ($this->_connected_to[0] != $uri->getHost() || $this->_connected_to[1] != $uri->getPort()) {
         require_once 'Zend/Http/Client/Adapter/Exception.php';
         throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong host");
     }
     // set URL
     curl_setopt($this->_curl, CURLOPT_URL, $uri->__toString());
     // ensure correct curl call
     $curlValue = true;
     switch ($method) {
         case Zend_Http_Client::GET:
             $curlMethod = CURLOPT_HTTPGET;
             break;
         case Zend_Http_Client::POST:
             $curlMethod = CURLOPT_POST;
             break;
         case Zend_Http_Client::PUT:
             // There are two different types of PUT request, either a Raw Data string has been set
             // or CURLOPT_INFILE and CURLOPT_INFILESIZE are used.
             if (is_resource($body)) {
                 $this->_config['curloptions'][CURLOPT_INFILE] = $body;
             }
             if (isset($this->_config['curloptions'][CURLOPT_INFILE])) {
                 // Now we will probably already have Content-Length set, so that we have to delete it
                 // from $headers at this point:
                 foreach ($headers as $k => $header) {
                     if (preg_match('/Content-Length:\\s*(\\d+)/i', $header, $m)) {
                         if (is_resource($body)) {
                             $this->_config['curloptions'][CURLOPT_INFILESIZE] = (int) $m[1];
                         }
                         unset($headers[$k]);
                     }
                 }
                 if (!isset($this->_config['curloptions'][CURLOPT_INFILESIZE])) {
                     require_once 'Zend/Http/Client/Adapter/Exception.php';
                     throw new Zend_Http_Client_Adapter_Exception("Cannot set a file-handle for cURL option CURLOPT_INFILE without also setting its size in CURLOPT_INFILESIZE.");
                 }
                 if (is_resource($body)) {
                     $body = '';
                 }
                 $curlMethod = CURLOPT_PUT;
             } else {
                 $curlMethod = CURLOPT_CUSTOMREQUEST;
                 $curlValue = "PUT";
             }
             break;
         case Zend_Http_Client::DELETE:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "DELETE";
             break;
         case Zend_Http_Client::OPTIONS:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "OPTIONS";
             break;
         case Zend_Http_Client::TRACE:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "TRACE";
             break;
         case Zend_Http_Client::HEAD:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "HEAD";
             break;
         default:
             // For now, through an exception for unsupported request methods
             require_once 'Zend/Http/Client/Adapter/Exception.php';
             throw new Zend_Http_Client_Adapter_Exception("Method currently not supported");
     }
     if (is_resource($body) && $curlMethod != CURLOPT_PUT) {
         require_once 'Zend/Http/Client/Adapter/Exception.php';
         throw new Zend_Http_Client_Adapter_Exception("Streaming requests are allowed only with PUT");
     }
     // get http version to use
     $curlHttp = $httpVersion == 1.1 ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
     // mark as HTTP request and set HTTP method
     curl_setopt($this->_curl, $curlHttp, true);
     curl_setopt($this->_curl, $curlMethod, $curlValue);
     if ($this->out_stream) {
         // headers will be read into the response
         curl_setopt($this->_curl, CURLOPT_HEADER, false);
         curl_setopt($this->_curl, CURLOPT_HEADERFUNCTION, array($this, "readHeader"));
         // and data will be written into the file
         curl_setopt($this->_curl, CURLOPT_FILE, $this->out_stream);
     } else {
         // ensure headers are also returned
         curl_setopt($this->_curl, CURLOPT_HEADER, true);
         // ensure actual response is returned
         curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
     }
     // set additional headers
     $headers['Accept'] = '';
     curl_setopt($this->_curl, CURLOPT_HTTPHEADER, $headers);
     /**
      * Make sure POSTFIELDS is set after $curlMethod is set:
      * @link http://de2.php.net/manual/en/function.curl-setopt.php#81161
      */
     if ($method == Zend_Http_Client::POST) {
         curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
     } elseif ($curlMethod == CURLOPT_PUT) {
         // this covers a PUT by file-handle:
         // Make the setting of this options explicit (rather than setting it through the loop following a bit lower)
         // to group common functionality together.
         curl_setopt($this->_curl, CURLOPT_INFILE, $this->_config['curloptions'][CURLOPT_INFILE]);
         curl_setopt($this->_curl, CURLOPT_INFILESIZE, $this->_config['curloptions'][CURLOPT_INFILESIZE]);
         unset($this->_config['curloptions'][CURLOPT_INFILE]);
         unset($this->_config['curloptions'][CURLOPT_INFILESIZE]);
     } elseif ($method == Zend_Http_Client::PUT) {
         // This is a PUT by a setRawData string, not by file-handle
         curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
     }
     // set additional curl options
     if (isset($this->_config['curloptions'])) {
         foreach ((array) $this->_config['curloptions'] as $k => $v) {
             if (!in_array($k, $this->_invalidOverwritableCurlOptions)) {
                 if (curl_setopt($this->_curl, $k, $v) == false) {
                     require_once 'Zend/Http/Client/Exception.php';
                     throw new Zend_Http_Client_Exception(sprintf("Unknown or erroreous cURL option '%s' set", $k));
                 }
             }
         }
     }
     // send the request
     $response = curl_exec($this->_curl);
     // if we used streaming, headers are already there
     if (!is_resource($this->out_stream)) {
         $this->_response = $response;
     }
     $request = curl_getinfo($this->_curl, CURLINFO_HEADER_OUT);
     $request .= $body;
     if (empty($this->_response)) {
         require_once 'Zend/Http/Client/Exception.php';
         throw new Zend_Http_Client_Exception("Error in cURL request: " . curl_error($this->_curl));
     }
     // cURL automatically decodes chunked-messages, this means we have to disallow the Zend_Http_Response to do it again
     if (stripos($this->_response, "Transfer-Encoding: chunked\r\n")) {
         $this->_response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $this->_response);
     }
     // Eliminate multiple HTTP responses.
     do {
         $parts = preg_split('|(?:\\r?\\n){2}|m', $this->_response, 2);
         $again = false;
         if (isset($parts[1]) && preg_match("|^HTTP/1\\.[01](.*?)\r\n|mi", $parts[1])) {
             $this->_response = $parts[1];
             $again = true;
         }
     } while ($again);
     // cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string:
     if (stripos($this->_response, "HTTP/1.0 200 Connection established\r\n\r\n") !== false) {
         $this->_response = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $this->_response);
     }
     return $request;
 }
예제 #4
0
 /**
  * Send request to the remote server
  *
  * @param string $method
  * @param Zend_Uri_Http $uri
  * @param float $http_ver
  * @param array  $headers
  * @param string $body
  */
 public function write($method, $uri, $http_ver = 1.1, $headers = array(), $body = '')
 {
     // Make sure we're properly connected
     if (!$this->socket) {
         throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are not connected");
     }
     $host = $uri->getHost();
     $host = strtolower($uri->getScheme()) == 'https' ? 'ssl://' . $host : $host;
     if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {
         throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong host");
     }
     // Build request headers
     $request = "{$method} {$uri->__toString()} HTTP/{$http_ver}\r\n";
     foreach ($headers as $k => $v) {
         if (is_string($k)) {
             $v = ucfirst($k) . ": {$v}";
         }
         $request .= "{$v}\r\n";
     }
     // Add the request body
     $request .= "\r\n" . $body;
     // Send the request
     fwrite($this->socket, $request);
 }
예제 #5
0
 /**
  * Send request to the remote server
  *
  * @param string        $method
  * @param Zend_Uri_Http $uri
  * @param float         $http_ver
  * @param array         $headers
  * @param string        $body
  */
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     // set URL
     curl_setopt($this->curl, CURLOPT_URL, $uri->__toString());
     // Make sure we're properly connected
     if (!$this->curl) {
         throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are not connected");
     }
     if ($this->connected_to[0] != $uri->getHost() || $this->connected_to[1] != $uri->getPort()) {
         throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong host");
     }
     // ensure correct curl call
     if ($method == Zend_Http_Client::GET) {
         $curlMethod = CURLOPT_HTTPGET;
     } elseif ($method == Zend_Http_Client::POST) {
         $curlMethod = CURLOPT_POST;
     } else {
         // TODO: use CURLOPT_PUT for PUT requests, CURLOPT_CUSTOMREQUEST for other types of calls
         // For now, through an exception for unsupported request methods
         throw new Zend_Http_Client_Adapter_Exception("Method currently not supported");
     }
     // get http version to use
     $curlHttp = ($http_ver = 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
     curl_setopt($this->curl, $curlMethod, true);
     curl_setopt($this->curl, $curlHttp, true);
     // ensure headers are also returned
     curl_setopt($this->curl, CURLOPT_HEADER, true);
     // ensure actual response is returned
     curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
     // set additional headers
     curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
     if ($method == Zend_Http_Client::POST) {
         curl_setopt($this->curl, CURLOPT_POSTFIELDS, $body);
     }
     // send the request
     $this->response = curl_exec($this->curl);
 }
예제 #6
0
 /**
  * Send request to the proxy server
  *
  * @param string        $method
  * @param Zend_Uri_Http $uri
  * @param string        $http_ver
  * @param array         $headers
  * @param string        $body
  * @return string Request as string
  */
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     // set URL
     curl_setopt($this->curl, CURLOPT_URL, $uri->__toString());
     //        var_dump($this->curl);
     // Make sure we're properly connected
     //        if (! $this->curl)
     //            require_once 'Zend/Http/Client/Adapter/Exception.php';
     //            throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are not connected");
     //        if ($this->connected_to[0] != $uri->getHost() || $this->connected_to[1] != $uri->getPort())
     //            require_once 'Zend/Http/Client/Adapter/Exception.php';
     //            throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong host");
     // ensure correct curl call
     if ($method == Zend_Http_Client::GET) {
         $curlMethod = CURLOPT_HTTPGET;
     } elseif ($method == Zend_Http_Client::POST) {
         $curlMethod = CURLOPT_POST;
     } else {
         // TODO: use CURLOPT_PUT for PUT requests, CURLOPT_CUSTOMREQUEST for other types of calls
         // For now, through an exception for unsupported request methods
         require_once 'Zend/Http/Client/Adapter/Exception.php';
         throw new Zend_Http_Client_Adapter_Exception("Method currently not supported");
     }
     // get http version to use
     $curlHttp = ($http_ver = 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
     curl_setopt($this->curl, $curlMethod, true);
     curl_setopt($this->curl, $curlHttp, true);
     if ($uri->getScheme() == 'https') {
         curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, FALSE);
     }
     $host = $this->config['proxy_host'];
     $port = $this->config['proxy_port'];
     var_dump($host);
     var_dump($port);
     curl_setopt($this->curl, CURLOPT_PROXY, $host);
     curl_setopt($this->curl, CURLOPT_PROXYPORT, $port);
     // ensure headers are also returned
     curl_setopt($this->curl, CURLOPT_HEADER, false);
     // ensure actual response is returned
     curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
     // set additional headers
     curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
     //        curl_setopt($this->curl, CURLOPT_ENCODING, "gzip");
     //        var_dump($this->config);
     //        if(!$this->config['followlocation']){
     //            var_dump("OFF followlocation");
     //            curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 0);
     //        } else {
     //            var_dump("ON followlocation");
     //            curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 1);
     //        }
     curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 0);
     curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->config['timeout']);
     $ob =& $this;
     curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, array(&$ob, 'readHeader'));
     if ($method == Zend_Http_Client::POST) {
         curl_setopt($this->curl, CURLOPT_POSTFIELDS, $body);
     }
     // send the request
     $this->response = curl_exec($this->curl);
     $this->response = $this->getHeaders() . $this->response;
     $con_est_str = "HTTP/1.0 200 Connection established";
     if (strstr($this->response, $con_est_str) !== false) {
         $response = substr($this->response, strlen($con_est_str) + strlen("\r\n\r\n"));
         $this->response = $response;
     } else {
         if ($this->response === false) {
             require_once 'Zend/Http/Client/Adapter/Exception.php';
             throw new Zend_Http_Client_Adapter_Exception("\nCurl error: " . curl_error($this->curl) . "\n");
         }
     }
 }
예제 #7
0
파일: Curl.php 프로젝트: reoring/sabel
 /**
  * Send request to the remote server
  *
  * @param  string        $method
  * @param  Zend_Uri_Http $uri
  * @param  float         $http_ver
  * @param  array         $headers
  * @param  string        $body
  * @return string        $request
  * @throws Zend_Http_Client_Adapter_Exception If connection fails, connected to wrong host, no PUT file defined, unsupported method, or unsupported cURL option
  */
 public function write($method, $uri, $http_ver = "1.1", $headers = array(), $body = "")
 {
     // Make sure we're properly connected
     if (!$this->_curl) {
         $message = __METHOD__ . "() Trying to write but we are not connected.";
         throw new Sabel_Exception_Runtime($message);
     }
     if ($this->_connected_to[0] != $uri->host || $this->_connected_to[1] != $uri->port) {
         $message = __METHOD__ . "() Trying to write but we are connected to the wrong host.";
         throw new Sabel_Exception_Runtime($message);
     }
     // set URL
     curl_setopt($this->_curl, CURLOPT_URL, $uri->__toString());
     // ensure correct curl call
     $curlValue = true;
     switch ($method) {
         case Sabel_Http_Client::GET:
             $curlMethod = CURLOPT_HTTPGET;
             break;
         case Sabel_Http_Client::POST:
             $curlMethod = CURLOPT_POST;
             break;
         case Sabel_Http_Client::PUT:
             // There are two different types of PUT request, either a Raw Data string has been set
             // or CURLOPT_INFILE and CURLOPT_INFILESIZE are used.
             if (isset($this->_config["curloptions"][CURLOPT_INFILE])) {
                 if (!isset($this->_config["curloptions"][CURLOPT_INFILESIZE])) {
                     $message = __METHOD__ . "() Cannot set a file-handle for cURL option CURLOPT_INFILE " . "without also set its size in CURLOPT_INFILESIZE.";
                     throw new Sabel_Exception_Runtime($message);
                 }
                 // Now we will probably already have Content-Length set, so that we have to delete it
                 // from $headers at this point:
                 foreach ($headers as $k => $header) {
                     if (stristr($header, "Content-Length:") !== false) {
                         unset($headers[$k]);
                     }
                 }
                 $curlMethod = CURLOPT_PUT;
             } else {
                 $curlMethod = CURLOPT_CUSTOMREQUEST;
                 $curlValue = "PUT";
             }
             break;
         case Sabel_Http_Client::DELETE:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "DELETE";
             break;
         case Sabel_Http_Client::OPTIONS:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "OPTIONS";
             break;
         case Sabel_Http_Client::TRACE:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "TRACE";
             break;
         default:
             // For now, through an exception for unsupported request methods
             $message = __METHOD__ . "() Method currently not supported.";
             throw new Sabel_Exception_Runtime($message);
     }
     // get http version to use
     $curlHttp = ($http_ver = 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
     // mark as HTTP request and set HTTP method
     curl_setopt($this->_curl, $curlHttp, true);
     curl_setopt($this->_curl, $curlMethod, $curlValue);
     // ensure headers are also returned
     curl_setopt($this->_curl, CURLOPT_HEADER, true);
     // ensure actual response is returned
     curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
     // set additional headers
     $headers["Accept"] = "";
     curl_setopt($this->_curl, CURLOPT_HTTPHEADER, $headers);
     /**
      * Make sure POSTFIELDS is set after $curlMethod is set:
      * @link http://de2.php.net/manual/en/function.curl-setopt.php#81161
      */
     if ($method == Sabel_Http_Client::POST) {
         curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
     } elseif ($curlMethod == CURLOPT_PUT) {
         // this covers a PUT by file-handle:
         // Make the setting of this options explicit (rather than setting it through the loop following a bit lower)
         // to group common functionality together.
         curl_setopt($this->_curl, CURLOPT_INFILE, $this->_config["curloptions"][CURLOPT_INFILE]);
         curl_setopt($this->_curl, CURLOPT_INFILESIZE, $this->_config["curloptions"][CURLOPT_INFILESIZE]);
         unset($this->_config["curloptions"][CURLOPT_INFILE]);
         unset($this->_config["curloptions"][CURLOPT_INFILESIZE]);
     } elseif ($method == Sabel_Http_Client::PUT) {
         // This is a PUT by a setRawData string, not by file-handle
         curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
     }
     // set additional curl options
     if (isset($this->_config["curloptions"])) {
         foreach ((array) $this->_config["curloptions"] as $k => $v) {
             if (!in_array($k, $this->_invalidOverwritableCurlOptions)) {
                 if (curl_setopt($this->_curl, $k, $v) == false) {
                     $message = __METHOD__ . "() Unknown or erroreous cURL option '%s' set.";
                     throw new Sabel_Exception_Runtime(sprintf($message, $k));
                 }
             }
         }
     }
     // send the request
     $this->_response = curl_exec($this->_curl);
     $request = curl_getinfo($this->_curl, CURLINFO_HEADER_OUT);
     $request .= $body;
     if (empty($this->_response)) {
         $message = __METHOD__ . "() Error in cURL request: " . curl_error($this->_curl);
         throw new Sabel_Exception_Runtime($message);
     }
     // cURL automatically decodes chunked-messages, this means we have to disallow the Zend_Http_Response to do it again
     if (stripos($this->_response, "Transfer-Encoding: chunked\r\n")) {
         $this->_response = str_ireplace("Transfer-Encoding: chunked\r\n", "", $this->_response);
     }
     // Eliminate multiple HTTP responses.
     do {
         $parts = preg_split('|(?:\\r?\\n){2}|m', $this->_response, 2);
         $again = false;
         if (isset($parts[1]) && preg_match("|^HTTP/1\\.[01](.*?)\r\n|mi", $parts[1])) {
             $this->_response = $parts[1];
             $again = true;
         }
     } while ($again);
     // cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string:
     if (stripos($this->_response, "HTTP/1.0 200 Connection established\r\n\r\n") !== false) {
         $this->_response = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", "", $this->_response);
     }
     return $request;
 }
 /**
  * Send request to the remote server
  *
  * @param  string        $method
  * @param  Zend_Uri_Http $uri
  * @param  float         $http_ver
  * @param  array         $headers
  * @param  string        $body
  * @return string        $request
  * @throws Zend_Http_Client_Adapter_Exception If connection fails, connected to wrong host, no PUT file defined, unsupported method, or unsupported cURL option
  */
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     // Make sure we're properly connected
     if (!$this->_curl) {
         require_once 'Zend/Http/Client/Adapter/Exception.php';
         throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are not connected");
     }
     if ($this->_connected_to[0] != $uri->getHost() || $this->_connected_to[1] != $uri->getPort()) {
         require_once 'Zend/Http/Client/Adapter/Exception.php';
         throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong host");
     }
     // set URL
     curl_setopt($this->_curl, CURLOPT_URL, $uri->__toString());
     // ensure correct curl call
     $curlValue = true;
     switch ($method) {
         case Zend_Http_Client::GET:
             $curlMethod = CURLOPT_HTTPGET;
             break;
         case Zend_Http_Client::POST:
             $curlMethod = CURLOPT_POST;
             break;
         case Zend_Http_Client::PUT:
             // There are two different types of PUT request, either a Raw Data string has been set
             // or CURLOPT_INFILE and CURLOPT_INFILESIZE are used.
             if (isset($this->_config['curloptions'][CURLOPT_INFILE])) {
                 if (!isset($this->_config['curloptions'][CURLOPT_INFILESIZE])) {
                     require_once 'Zend/Http/Client/Adapter/Exception.php';
                     throw new Zend_Http_Client_Adapter_Exception("Cannot set a file-handle for cURL option CURLOPT_INFILE without also setting its size in CURLOPT_INFILESIZE.");
                 }
                 // Now we will probably already have Content-Length set, so that we have to delete it
                 // from $headers at this point:
                 foreach ($headers as $k => $header) {
                     if (stristr($header, "Content-Length:") !== false) {
                         unset($headers[$k]);
                     }
                 }
                 $curlMethod = CURLOPT_PUT;
             } else {
                 $curlMethod = CURLOPT_CUSTOMREQUEST;
                 $curlValue = "PUT";
             }
             break;
         case Zend_Http_Client::DELETE:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "DELETE";
             break;
         case Zend_Http_Client::OPTIONS:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "OPTIONS";
             break;
         case Zend_Http_Client::TRACE:
             $curlMethod = CURLOPT_CUSTOMREQUEST;
             $curlValue = "TRACE";
             break;
         default:
             // For now, through an exception for unsupported request methods
             require_once 'Zend/Http/Client/Adapter/Exception.php';
             throw new Zend_Http_Client_Adapter_Exception("Method currently not supported");
     }
     // get http version to use
     $curlHttp = ($http_ver = 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
     // mark as HTTP request and set HTTP method
     curl_setopt($this->_curl, $curlHttp, true);
     curl_setopt($this->_curl, $curlMethod, $curlValue);
     // ensure headers are also returned
     curl_setopt($this->_curl, CURLOPT_HEADER, true);
     // ensure actual response is returned
     curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
     // set additional headers
     $headers['Accept'] = '';
     curl_setopt($this->_curl, CURLOPT_HTTPHEADER, $headers);
     /**
      * Make sure POSTFIELDS is set after $curlMethod is set:
      * @link http://de2.php.net/manual/en/function.curl-setopt.php#81161
      */
     if ($method == Zend_Http_Client::POST) {
         curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
     } elseif ($curlMethod == CURLOPT_PUT) {
         // this covers a PUT by file-handle:
         // Make the setting of this options explicit (rather than setting it through the loop following a bit lower)
         // to group common functionality together.
         curl_setopt($this->_curl, CURLOPT_INFILE, $this->_config['curloptions'][CURLOPT_INFILE]);
         curl_setopt($this->_curl, CURLOPT_INFILESIZE, $this->_config['curloptions'][CURLOPT_INFILESIZE]);
         unset($this->_config['curloptions'][CURLOPT_INFILE]);
         unset($this->_config['curloptions'][CURLOPT_INFILESIZE]);
     } elseif ($method == Zend_Http_Client::PUT) {
         // This is a PUT by a setRawData string, not by file-handle
         curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
     }
     // set additional curl options
     if (isset($this->_config['curloptions'])) {
         foreach ((array) $this->_config['curloptions'] as $k => $v) {
             if (!in_array($k, $this->_invalidOverwritableCurlOptions)) {
                 if (curl_setopt($this->_curl, $k, $v) == false) {
                     require_once 'Zend/Http/Client/Exception.php';
                     throw new Zend_Http_Client_Exception(sprintf("Unknown or erroreous cURL option '%s' set", $k));
                 }
             }
         }
     }
     // send the request
     $this->_response = curl_exec($this->_curl);
     $request = curl_getinfo($this->_curl, CURLINFO_HEADER_OUT);
     $request .= $body;
     if (empty($this->_response)) {
         require_once 'Zend/Http/Client/Exception.php';
         throw new Zend_Http_Client_Exception("Error in cURL request: " . curl_error($this->_curl));
     }
     // cURL automatically decodes chunked-messages, this means we have to disallow the Zend_Http_Response to do it again
     if (stripos($this->_response, "Transfer-Encoding: chunked\r\n")) {
         $this->_response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $this->_response);
     }
     // TODO: Probably the pattern for multiple handshake requests is always the same, several HTTP codes in the response. Use that information?
     // cURL automactically handles Expect: 100-continue; and its responses. Delete the HTTP 100 CONTINUE from a response
     // because it messes up Zend_Http_Response parsing
     if (stripos($this->_response, "HTTP/1.1 100 Continue\r\n\r\n") !== false) {
         $this->_response = str_ireplace("HTTP/1.1 100 Continue\r\n\r\n", '', $this->_response);
     }
     // cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string:
     if (stripos($this->_response, "HTTP/1.0 200 Connection established\r\n\r\n") !== false) {
         $this->_response = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $this->_response);
     }
     return $request;
 }