/** * Callback function called by cURL for saving the response body * * @param resource cURL handle (not used) * @param string part of the response body * @return integer number of bytes saved * @see Diglin_HTTP_Request2_Response::appendBody() */ protected function callbackWriteBody($ch, $string) { // cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if // response doesn't start with proper HTTP status line (see bug #15716) if (empty($this->response)) { throw new Diglin_HTTP_Request2_Exception("Malformed response: {$string}"); } if ($this->request->getConfig('store_body')) { $this->response->appendBody($string); } $this->request->setLastEvent('receivedBodyPart', $string); return strlen($string); }
/** * Creates a new Diglin_HTTP_Request2_Response object from a file * * @param resource file pointer returned by fopen() * @return Diglin_HTTP_Request2_Response * @throws Diglin_HTTP_Request2_Exception */ public static function createResponseFromFile($fp) { $response = new Diglin_HTTP_Request2_Response(fgets($fp)); do { $headerLine = fgets($fp); $response->parseHeaderLine($headerLine); } while ('' != trim($headerLine)); while (!feof($fp)) { $response->appendBody(fread($fp, 8192)); } return $response; }