file reader fix

This commit is contained in:
kremsy 2015-10-13 19:12:27 +02:00
parent 07fa365d1a
commit 3f7c4a50a6
2 changed files with 21 additions and 3 deletions

View File

@ -103,7 +103,7 @@ class AsyncHttpRequest {
* @param Request $request
*/
private function processRequest(Request $request) {
$request->addListener('complete', function (Event $event) use (&$function) {
$request->addListener('complete', function (Event $event) {
$error = null;
$content = null;
if ($event->response->hasError()) {
@ -111,10 +111,10 @@ class AsyncHttpRequest {
} else {
$content = $event->response->getContent();
}
call_user_func($function, $content, $error);
call_user_func($this->function, $content, $error);
});
$fileReader = new AsynchronousFileReader($this->maniaControl);
$fileReader = $this->maniaControl->getFileReader();
$fileReader->addRequest($request);
}

View File

@ -58,6 +58,24 @@ class AsynchronousFileReader {
}
}
/**
* Create a new cURL Request for the given URL, DO NOT CALL MANUALLY!
*
* @param string $url
* @return Request
*/
public function newRequest($url) {
$request = new Request($url);
$request->getOptions()->set(CURLOPT_TIMEOUT, 60)->set(CURLOPT_HEADER, false)// don't display response header
->set(CURLOPT_CRLF, true)// linux line feed
->set(CURLOPT_ENCODING, '')// accept encoding
->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION)// user-agent
->set(CURLOPT_RETURNTRANSFER, true); // return instead of output content
return $request;
}
/**
* Load a Remote File
*