Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Parse/HttpClients/ParseStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function get($url)
try {
// get our response
$response = file_get_contents($url, false, $this->stream);
$this->errorMessage = null;
$this->errorCode = null;
} catch (\Exception $e) {
// set our error message/code and return false
$this->errorMessage = $e->getMessage();
Expand Down
13 changes: 6 additions & 7 deletions src/Parse/HttpClients/ParseStreamHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ public function setup()
$this->options['ssl'] = array(
'verify_peer' => true,
'verify_peer_name' => true,
'allow_self_signed' => true, // All root certificates are self-signed
'follow_location' => 1
'allow_self_signed' => true // All root certificates are self-signed
);
}

Expand Down Expand Up @@ -233,11 +232,11 @@ public function send($url, $method = 'GET', $data = array())
// get our response headers
$rawHeaders = $this->parseStream->getResponseHeaders();

if ($response === false || !$rawHeaders) {
// set an error and code
$this->streamErrorMessage = $this->parseStream->getErrorMessage();
$this->streamErrorCode = $this->parseStream->getErrorCode();
} else {
// set any error and code
$this->streamErrorMessage = $this->parseStream->getErrorMessage();
$this->streamErrorCode = $this->parseStream->getErrorCode();

if ($response !== false && $rawHeaders) {
// set our response headers
$this->responseHeaders = self::formatHeaders($rawHeaders);

Expand Down
19 changes: 8 additions & 11 deletions src/Parse/ParseFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static function _createFromServer($name, $url)
/**
* Encode to associative array representation.
*
* @return string
* @return array
*/
public function _encode()
{
Expand Down Expand Up @@ -242,21 +242,18 @@ private function upload($useMasterKey = false)
*/
private function download()
{
$rest = curl_init();
curl_setopt($rest, CURLOPT_URL, $this->url);
curl_setopt($rest, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rest, CURLOPT_BINARYTRANSFER, 1);
$response = curl_exec($rest);
if (curl_errno($rest)) {
throw new ParseException(curl_error($rest), curl_errno($rest));
$httpClient = ParseClient::getHttpClient();
$httpClient->setup();
$response = $httpClient->send($this->url);
if ($httpClient->getErrorCode()) {
throw new ParseException($httpClient->getErrorMessage(), $httpClient->getErrorCode());
}
$httpStatus = curl_getinfo($rest, CURLINFO_HTTP_CODE);
$httpStatus = $httpClient->getResponseStatusCode();
if ($httpStatus > 399) {
throw new ParseException('Download failed, file may have been deleted.', $httpStatus);
}
$this->mimeType = curl_getinfo($rest, CURLINFO_CONTENT_TYPE);
$this->mimeType = $httpClient->getResponseContentType();
$this->data = $response;
curl_close($rest);

return $response;
}
Expand Down
12 changes: 10 additions & 2 deletions tests/Parse/ParseFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Parse\Test;

use Parse\ParseException;
use Parse\ParseFile;
use Parse\ParseObject;
use Parse\ParseQuery;
Expand Down Expand Up @@ -93,7 +92,16 @@ public function testParsefileDeleteUnsaved()
*/
public function testParseFileDownloadBadURL()
{
$this->setExpectedException('\Parse\ParseException', '', 6);
global $USE_CLIENT_STREAM;

if (!isset($USE_CLIENT_STREAM)) {
// curl exception expectation
$this->setExpectedException('\Parse\ParseException', '', 6);
} else {
// stream exception expectation
$this->setExpectedException('\Parse\ParseException', '', 2);
}

$file = ParseFile::_createFromServer('file.txt', 'http://404.example.com');
$file->getData();
}
Expand Down