1
0
Fork 0

Curl Response Refactoring

- refactored Network::post()
- replaced every Network::post() execution with the new Curl container
This commit is contained in:
Philipp Holzer 2018-10-10 21:15:26 +02:00
commit 7c73e8634c
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
10 changed files with 24 additions and 25 deletions

View file

@ -1469,16 +1469,17 @@ class DFRN
$content_type = ($public_batch ? "application/magic-envelope+xml" : "application/json");
$xml = Network::post($dest_url, $envelope, ["Content-Type: ".$content_type]);
$postResult = Network::post($dest_url, $envelope, ["Content-Type: ".$content_type]);
$xml = $postResult->getBody();
$curl_stat = Network::getCurl()->getCode();
$curl_stat = $postResult->getReturnCode();
if (empty($curl_stat) || empty($xml)) {
logger('Empty answer from ' . $contact['id'] . ' - ' . $dest_url);
Contact::markForArchival($contact);
return -9; // timed out
}
if (($curl_stat == 503) && (stristr(Network::getCurl()->getHeaders(), 'retry-after'))) {
if (($curl_stat == 503) && (stristr($postResult->getHeader(), 'retry-after'))) {
Contact::markForArchival($contact);
return -10;
}

View file

@ -3079,8 +3079,8 @@ class Diaspora
if (!intval(Config::get("system", "diaspora_test"))) {
$content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]);
$return_code = Network::getCurl()->getCode();
$postResult = Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]);
$return_code = $postResult->getReturnCode();
} else {
logger("test_mode");
return 200;
@ -3089,7 +3089,7 @@ class Diaspora
logger("transmit: ".$logid."-".$guid." to ".$dest_url." returns: ".$return_code);
if (!$return_code || (($return_code == 503) && (stristr(Network::getCurl()->getHeaders(), "retry-after")))) {
if (!$return_code || (($return_code == 503) && (stristr($postResult->getHeaders(), "retry-after")))) {
if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::ACCOUNT_TYPE_RELAY)) {
logger("queue message");
// queue message for redelivery

View file

@ -133,13 +133,12 @@ class Salmon
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them
Network::post($url, $salmon, [
$postResult = Network::post($url, $salmon, [
'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon)
]);
$a = get_app();
$return_code = Network::getCurl()->getCode();
$return_code = $postResult->getReturnCode();
// check for success, e.g. 2xx
@ -159,11 +158,11 @@ class Salmon
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them
Network::post($url, $salmon, [
$postResult = Network::post($url, $salmon, [
'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon)
]);
$return_code = Network::getCurl()->getCode();
$return_code = $postResult->getReturnCode();
}
if ($return_code > 299) {
@ -182,10 +181,10 @@ class Salmon
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them
Network::post($url, $salmon, [
$postResult = Network::post($url, $salmon, [
'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon)]);
$return_code = Network::getCurl()->getCode();
$return_code = $postResult->getReturnCode();
}
logger('slapper for '.$url.' returned ' . $return_code);