/** * Prepare the request headers * * @return string */ protected function _prepare_headers() { $headers = "{$this->method} {$this->uri->getPath()}"; // Get the original GET parameters from the URL $query = $this->uri->getQuery(); // Get the GET parameters that were added using the setParameterGet() method if (count($this->paramsGet) > 0) { if ($query) { $query .= '&'; } // Flatten the GET parameters array $params = $this->_getParametersRecursive($this->paramsGet, true); foreach ($params as $gp) { $query .= "{$gp[0]}={$gp[1]}&"; } $query = substr($query, 0, strlen($query) - 1); } if ($query) { $headers .= "?{$query}"; } $headers .= " HTTP/{$this->http_version}\r\n"; // Set the host header if (!isset($this->headers['host'])) { $host = $this->uri->getHost() . ($this->uri->getPort() == 80 ? '' : ':' . $this->uri->getPort()); $this->setHeader('host', $host); } // Set the connection header // For now, only support closed connections if (!isset($this->headers['connection'])) { $this->setHeader('connection', 'close'); } // Set the content-type header if (!isset($this->headers['content-type']) && isset($this->enctype)) { $this->setHeader('content-type', $this->enctype); } // Set the user agent header if (!isset($this->headers['user-agent']) && isset($this->user_agent)) { $this->setHeader('user-agent', $this->user_agent); } // Set HTTP authentication if needed if (is_array($this->auth)) { $this->setHeader('Authorization', self::encodeAuthHeader($this->auth['user'], $this->auth['password'], $this->auth['type'])); } // Load cookies from cookie jar if (isset($this->Cookiejar)) { $cookstr = $this->Cookiejar->getMatchingCookies($this->uri, true, Zend_Http_Cookiejar::COOKIE_STRING_CONCAT); if ($cookstr) { if (isset($this->headers['cookie'])) { $this->headers['cookie'] .= "; {$cookstr}"; } else { $this->setHeader('cookie', $cookstr); } } } // Compile the headers foreach ($this->headers as $name => $value) { if (is_array($value)) { foreach ($value as $subval) { $headers .= ucfirst($name) . ": {$subval}\r\n"; } } else { $headers .= ucfirst($name) . ": {$value}\r\n"; } } return $headers; }