Skip to content

Loading…

Fixing warnings triggered by cURL when no response is received. #1438

Merged
merged 1 commit into from

4 participants

@pasamio

This pull request resolves a situation where when no response from a server is received a PHP warning is thrown by the cURL transport. Instead the code triggering the warning is mitigated and additionally a check to see if there was any response data is added to validate a response was actually received or throw an exception.

@LouisLandry LouisLandry merged commit 233125f into joomla:staging
@piotr-cz

Please take a look at my PR #1022.
This is addressing same issue across all JHttpTransports

@elinw

Actually there's a difference between getting empty content and what you get from a bad url where in fact you are not going to get a normal repsonse code since there is no server.
$return = new JHttpResponse

I haven't tested it yet but I bet it isn't pretty if the $uri doesn't exist, it probably needs an exception and then JTransportCurl needs to handle that. And yes the error issue is a problem because php is going to send a notice before any exception gets thrown.

Needs to catch that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 8 additions and 1 deletion.
  1. +8 −1 libraries/joomla/http/transport/curl.php
View
9 libraries/joomla/http/transport/curl.php
@@ -169,6 +169,12 @@ protected function getResponse($content, $info)
// Create the response object.
$return = new JHttpResponse;
+ // Check if the content is actually a string.
+ if (!is_string($content))
+ {
+ throw new UnexpectedValueException('No HTTP response received.');
+ }
+
// Get the number of redirects that occurred.
$redirects = isset($info['redirect_count']) ? $info['redirect_count'] : 0;
@@ -187,7 +193,8 @@ protected function getResponse($content, $info)
// Get the response code from the first offset of the response headers.
preg_match('/[0-9]{3}/', array_shift($headers), $matches);
- $code = $matches[0];
+
+ $code = count($matches) ? $matches[0] : null;
if (is_numeric($code))
{
$return->code = (int) $code;
Something went wrong with that request. Please try again.