コード例 #1
0
 public function testLineBreaksCompatibility()
 {
     $response_text_lf = file_get_contents(dirname(__FILE__) . '/_files/response_lfonly');
     $res_lf = Zend_Http_Response::factory($response_text_lf);
     $response_text_crlf = file_get_contents(dirname(__FILE__) . '/_files/response_crlf');
     $res_crlf = Zend_Http_Response::factory($response_text_crlf);
     $this->assertEquals($res_lf->getHeadersAsString(true), $res_crlf->getHeadersAsString(true), 'Responses headers do not match');
     $this->assertEquals($res_lf->getBody(), $res_crlf->getBody(), 'Response bodies do not match');
 }
コード例 #2
0
ファイル: Abstract.php プロジェクト: jorgenils/zend-framework
 /**
  * Send the HTTP request and return a response
  *
  * @param string $method
  * @return Zend_Http_Response
  */
 public function request($method = null)
 {
     if (!$this->uri instanceof Zend_Uri_Http) {
         throw new Zend_Http_Exception("No valid URI has been passed to the client");
     }
     if ($method) {
         $this->setMethod($method);
     }
     // Prepare the request string
     $body = $this->_prepare_body();
     $headers = $this->_prepare_headers();
     $request = $headers . "\r\n" . $body;
     // Open the connection, send the request and read the response
     $sock = $this->_connect();
     $this->_write($sock, $request);
     $response = $this->_read($sock);
     $this->last_request = $request;
     return Zend_Http_Response::factory($response);
 }
コード例 #3
0
ファイル: Client.php プロジェクト: jorgenils/zend-framework
 /**
  * Send the HTTP request and return an HTTP response object
  *
  * @param string $method
  * @return Zend_Http_Response
  */
 public function request($method = null)
 {
     if (!$this->uri instanceof Zend_Uri_Http) {
         throw new Zend_Http_Client_Exception("No valid URI has been passed to the client");
     }
     if ($method) {
         $this->setMethod($method);
     }
     $this->redirectCounter = 0;
     $response = null;
     // Send the first request. If redirected, continue.
     do {
         // Clone the URI and add the additional GET parameters to it
         $uri = clone $this->uri;
         $uri_params = array();
         parse_str($uri->getQuery(), $uri_params);
         $uri->setQuery(array_merge($uri_params, $this->paramsGet));
         $body = $this->prepare_body();
         $headers = $this->prepare_headers();
         $request = implode("\r\n", $headers) . "\r\n" . $body;
         $this->last_request = $request;
         // Open the connection, send the request and read the response
         $this->adapter->connect($uri->getHost(), $uri->getPort(), $uri->getScheme() == 'https' ? true : false);
         $this->adapter->write($this->method, $uri, $this->config['httpversion'], $headers, $body);
         $response = Zend_Http_Response::factory($this->adapter->read());
         // Load cookies into cookie jar
         if (isset($this->Cookiejar)) {
             $this->Cookiejar->addCookiesFromResponse($response, $uri);
         }
         // If we got redirected, look for the Location header
         if ($response->isRedirect() && ($location = $response->getHeader('location'))) {
             // Check whether we send the exact same request again, or drop the parameters
             // and send a GET request
             if ($response->getStatus() == 303 || !$this->config['strictredirects'] && ($response->getStatus() == 302 || $response->getStatus() == 301)) {
                 $this->resetParameters();
                 $this->setMethod(self::GET);
             }
             // If we got a well formed absolute URI
             if (Zend_Uri_Http::check($location)) {
                 $this->setHeaders('host', null);
                 $this->setUri($location);
             } else {
                 // Split into path and query and set the query
                 list($location, $query) = explode('?', $location, 2);
                 $this->uri->setQueryString($query);
                 // Else, if we got just an absolute path, set it
                 if (strpos($location, '/') === 0) {
                     $this->uri->setPath($location);
                     // Else, assume we have a relative path
                 } else {
                     // Get the current path directory, removing any trailing slashes
                     $path = rtrim(dirname($this->uri->getPath()), "/");
                     $this->uri->setPath($path . '/' . $location);
                 }
             }
             $this->redirectCounter++;
         } else {
             // If we didn't get any location, stop redirecting
             break;
         }
     } while ($this->redirectCounter < $this->config['maxredirects']);
     return $response;
 }