Skip to content
Merged
Changes from 1 commit
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
22 changes: 15 additions & 7 deletions lib/Cleantalk/ApbctWP/HTTP/HTTPMultiRequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ public function executeMultiContract()
*/
public function fillMultiContract($http_multi_result)
{
// Handle HTTP request error
if (!empty($http_multi_result['error'])) {
$this->error_msg = __CLASS__ . ': HTTP_MULTI_RESULT ERROR' . $http_multi_result['error'];
return $this;
}

// Validate result is an array
if (!is_array($http_multi_result)) {
$this->error_msg = __CLASS__ . ': HTTP_MULTI_RESULT INVALID';
return $this;
}

// Handle HTTP request error
if (!empty($http_multi_result['error'])) {
$this->error_msg = __CLASS__ . ': HTTP_MULTI_RESULT ERROR' . $http_multi_result['error'];
return $this;
}
Comment thread
AntonV1211 marked this conversation as resolved.

// Fill each contract with corresponding response data
foreach ($this->contracts as $contract) {
if (isset($http_multi_result[$contract->url])) {
Expand Down Expand Up @@ -213,7 +213,15 @@ public function sendRequests($urls)
// Configure and execute multi-request
$http->setUrl($urls)
Comment thread
AntonV1211 marked this conversation as resolved.
->setPresets('get');
return $http->request();
$result = $http->request();

// CommonRequest::request() returns a single value instead of an associative
// array when only one URL is passed. Normalize to expected format.
if (count($urls) === 1 && !is_array($result)) {
return [$urls[0] => $result];
}

return $result;
Comment thread
AntonV1211 marked this conversation as resolved.
Outdated
Comment thread
AntonV1211 marked this conversation as resolved.
Outdated
}

/**
Expand Down
Loading