All URI, networking, and communication errors are using negative, 0, or NULL status codes.

In various locations, drupal_http_request() ensures this by negating a potential status code:

    // When a network error occurs, we use a negative number so it does not
    // clash with the HTTP status codes.
    $result->code = -$errno;

This was consistent until #156582: drupal_http_request() should support timeout setting came, which added:

/**
 * Error code indicating that the request made by drupal_http_request() exceeded
 * the specified timeout.
 */
define('HTTP_REQUEST_TIMEOUT', 1);

and directly returns:

  if ($info['timed_out']) {
    $result->code = HTTP_REQUEST_TIMEOUT;
    $result->error = 'request timed out';
    return $result;
  }

All application-level error handling logic that previously checked for

  // Catch 0, NULL, and any negative status code (networking errors).
  if ($response->code <= 0) exit;

now has to additionally check for the custom Drupalism and non-existing status code 1.

CommentFileSizeAuthor
drupal.http-timeout.0.patch449 bytessun

Comments

sun’s picture

Status: Active » Needs review
damien tournoud’s picture

Status: Needs review » Reviewed & tested by the community
dries’s picture

Committed to 8.x and 7.x. For 6.x we need to adjust #156582: drupal_http_request() should support timeout setting.

sun’s picture

Status: Reviewed & tested by the community » Fixed
c960657’s picture

Doesn't this collide with the $errno returned by fsockopen() ?

Automatically closed -- issue fixed for 2 weeks with no activity.