additional headers in asynchronousfilereader
This commit is contained in:
parent
30945a17e6
commit
6a8087cd95
@ -1,6 +1,8 @@
|
|||||||
###v0.162###
|
###v0.162###
|
||||||
#Additions
|
#Additions
|
||||||
- added typhinting ladderStat in Player object
|
- added typhinting ladderStat in Player object
|
||||||
|
- added optional AsynchronousFileReader Parameter for loadFile and postFile to set additional Headers
|
||||||
|
- added ServerLogin header for Mania-Exchange downloads
|
||||||
|
|
||||||
###v0.161###
|
###v0.161###
|
||||||
#Additions
|
#Additions
|
||||||
|
@ -38,10 +38,10 @@ class AsynchronousFileReader {
|
|||||||
|
|
||||||
public static function newRequestTest($url) {
|
public static function newRequestTest($url) {
|
||||||
$request = new Request($url);
|
$request = new Request($url);
|
||||||
$request->getOptions()->set(CURLOPT_TIMEOUT, 60)->set(CURLOPT_HEADER, false) // don't display response header
|
$request->getOptions()->set(CURLOPT_TIMEOUT, 60)->set(CURLOPT_HEADER, false)// don't display response header
|
||||||
->set(CURLOPT_CRLF, true) // linux line feed
|
->set(CURLOPT_CRLF, true)// linux line feed
|
||||||
->set(CURLOPT_ENCODING, '') // accept encoding
|
->set(CURLOPT_ENCODING, '')// accept encoding
|
||||||
->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION) // user-agent
|
->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION)// user-agent
|
||||||
->set(CURLOPT_RETURNTRANSFER, true); // return instead of output content
|
->set(CURLOPT_RETURNTRANSFER, true); // return instead of output content
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
@ -66,9 +66,9 @@ class AsynchronousFileReader {
|
|||||||
* @param callable $function
|
* @param callable $function
|
||||||
* @param string $contentType
|
* @param string $contentType
|
||||||
* @param int $keepAlive
|
* @param int $keepAlive
|
||||||
|
* @param array $headers Additional Headers
|
||||||
*/
|
*/
|
||||||
public function loadFile($url, callable $function, $contentType = 'UTF-8', $keepAlive = 0) {
|
public function loadFile($url, callable $function, $contentType = 'UTF-8', $keepAlive = 0, $headers = array()) {
|
||||||
$headers = array();
|
|
||||||
array_push($headers, 'Content-Type: ' . $contentType);
|
array_push($headers, 'Content-Type: ' . $contentType);
|
||||||
if ($keepAlive) {
|
if ($keepAlive) {
|
||||||
array_push($headers, 'Keep-Alive: ' . $keepAlive);
|
array_push($headers, 'Keep-Alive: ' . $keepAlive);
|
||||||
@ -76,7 +76,7 @@ class AsynchronousFileReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$request = $this->newRequest($url);
|
$request = $this->newRequest($url);
|
||||||
$request->getOptions()->set(CURLOPT_AUTOREFERER, true) // accept link reference
|
$request->getOptions()->set(CURLOPT_AUTOREFERER, true)// accept link reference
|
||||||
->set(CURLOPT_HTTPHEADER, $headers); // headers
|
->set(CURLOPT_HTTPHEADER, $headers); // headers
|
||||||
|
|
||||||
$request->addListener('complete', function (Event $event) use (&$function) {
|
$request->addListener('complete', function (Event $event) use (&$function) {
|
||||||
@ -101,10 +101,10 @@ class AsynchronousFileReader {
|
|||||||
*/
|
*/
|
||||||
protected function newRequest($url) {
|
protected function newRequest($url) {
|
||||||
$request = new Request($url);
|
$request = new Request($url);
|
||||||
$request->getOptions()->set(CURLOPT_TIMEOUT, 60)->set(CURLOPT_HEADER, false) // don't display response header
|
$request->getOptions()->set(CURLOPT_TIMEOUT, 60)->set(CURLOPT_HEADER, false)// don't display response header
|
||||||
->set(CURLOPT_CRLF, true) // linux line feed
|
->set(CURLOPT_CRLF, true)// linux line feed
|
||||||
->set(CURLOPT_ENCODING, '') // accept encoding
|
->set(CURLOPT_ENCODING, '')// accept encoding
|
||||||
->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION) // user-agent
|
->set(CURLOPT_USERAGENT, 'ManiaControl v' . ManiaControl::VERSION)// user-agent
|
||||||
->set(CURLOPT_RETURNTRANSFER, true); // return instead of output content
|
->set(CURLOPT_RETURNTRANSFER, true); // return instead of output content
|
||||||
return $request;
|
return $request;
|
||||||
}
|
}
|
||||||
@ -133,8 +133,8 @@ class AsynchronousFileReader {
|
|||||||
array_push($headers, 'Content-Encoding: gzip');
|
array_push($headers, 'Content-Encoding: gzip');
|
||||||
}
|
}
|
||||||
|
|
||||||
$request->getOptions()->set(CURLOPT_POST, true) // post method
|
$request->getOptions()->set(CURLOPT_POST, true)// post method
|
||||||
->set(CURLOPT_POSTFIELDS, $content) // post content field
|
->set(CURLOPT_POSTFIELDS, $content)// post content field
|
||||||
->set(CURLOPT_HTTPHEADER, $headers) // headers
|
->set(CURLOPT_HTTPHEADER, $headers) // headers
|
||||||
;
|
;
|
||||||
$request->addListener('complete', function (Event $event) use (&$function) {
|
$request->addListener('complete', function (Event $event) use (&$function) {
|
||||||
@ -161,10 +161,9 @@ class AsynchronousFileReader {
|
|||||||
* @param string $content
|
* @param string $content
|
||||||
* @param bool $compression
|
* @param bool $compression
|
||||||
* @param string $contentType
|
* @param string $contentType
|
||||||
|
* @param array $headers Additional Headers
|
||||||
*/
|
*/
|
||||||
public function postData($url, callable $function, $content, $compression = false, $contentType = 'text/xml; charset=UTF-8;') {
|
public function postData($url, callable $function, $content, $compression = false, $contentType = 'text/xml; charset=UTF-8;', $headers = array()) {
|
||||||
|
|
||||||
$headers = array();
|
|
||||||
array_push($headers, 'Content-Type: ' . $contentType);
|
array_push($headers, 'Content-Type: ' . $contentType);
|
||||||
array_push($headers, 'Keep-Alive: timeout=600, max=2000');
|
array_push($headers, 'Keep-Alive: timeout=600, max=2000');
|
||||||
array_push($headers, 'Connection: Keep-Alive');
|
array_push($headers, 'Connection: Keep-Alive');
|
||||||
@ -176,8 +175,8 @@ class AsynchronousFileReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$request = $this->newRequest($url);
|
$request = $this->newRequest($url);
|
||||||
$request->getOptions()->set(CURLOPT_POST, true) // post method
|
$request->getOptions()->set(CURLOPT_POST, true)// post method
|
||||||
->set(CURLOPT_POSTFIELDS, $content) // post content field
|
->set(CURLOPT_POSTFIELDS, $content)// post content field
|
||||||
->set(CURLOPT_HTTPHEADER, $headers) // headers
|
->set(CURLOPT_HTTPHEADER, $headers) // headers
|
||||||
;
|
;
|
||||||
$request->addListener('complete', function (Event $event) use (&$function) {
|
$request->addListener('complete', function (Event $event) use (&$function) {
|
||||||
|
@ -47,7 +47,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
|
|||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const VERSION = '0.161';
|
const VERSION = '0.162';
|
||||||
const API_VERSION = '2013-04-16';
|
const API_VERSION = '2013-04-16';
|
||||||
const MIN_DEDIVERSION = '2014-04-02_18_00';
|
const MIN_DEDIVERSION = '2014-04-02_18_00';
|
||||||
const SCRIPT_TIMEOUT = 10;
|
const SCRIPT_TIMEOUT = 10;
|
||||||
|
@ -366,7 +366,7 @@ class MapManager implements CallbackListener, CommunicationListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->processMapFile($file, $mapInfo, $login, $update);
|
$this->processMapFile($file, $mapInfo, $login, $update);
|
||||||
});
|
}, 'UTF-8', 0, array("X-ManiaPlanet-ServerLogin: " . $this->maniaControl->getServer()->login));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user