Curl Response Refactoring

- extended Curl to parse Curl Response
- refactored Network::curl()
- replaced every Network::curl() execution with the new Curl container
This commit is contained in:
Philipp Holzer
2018-10-10 21:08:43 +02:00
parent 904fee3bed
commit 2dec8895a9
20 changed files with 466 additions and 382 deletions

View File

@@ -185,18 +185,17 @@ class OnePoll
. '&type=data&last_update=' . $last_update
. '&perm=' . $perm ;
$ret = Network::curl($url);
$curlResult = Network::curl($url);
if (!empty($ret["errno"]) && ($ret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
if (!$curlResult->isSuccess() && ($curlResult->getErrorNumber() == CURLE_OPERATION_TIMEDOUT)) {
// set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
Contact::markForArchival($contact);
return;
}
$handshake_xml = $ret['body'];
$html_code = Network::getCurl()->getCode();
$handshake_xml = $curlResult->getBody();
$html_code = $curlResult->getReturnCode();
logger('handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA);
@@ -319,17 +318,17 @@ class OnePoll
}
$cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-');
$ret = Network::curl($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]);
$curlResult = Network::curl($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]);
unlink($cookiejar);
if (!empty($ret["errno"]) && ($ret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
if (!$curlResult->isTimeout()) {
// set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
Contact::markForArchival($contact);
return;
}
$xml = $ret['body'];
$xml = $curlResult->getBody();
} elseif ($contact['network'] === Protocol::MAIL) {
logger("Mail: Fetching for ".$contact['addr'], LOGGER_DEBUG);