Projet

Général

Profil

Révision 503b3f7b

Ajouté par Assos Assos il y a environ 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/l10n_update/l10n_update.inc
258 258
 */
259 259
function l10n_update_http_check($url, $headers = array()) {
260 260
  $result = l10n_update_http_request($url, array('headers' => $headers, 'method' => 'HEAD'));
261
  if ($result && $result->code == '200') {
262
    $result->updated = isset($result->headers['last-modified']) ? strtotime($result->headers['last-modified']) : 0;
261
  if (!isset($result->error)) {
262
    if ($result && $result->code == 200) {
263
      $result->updated = isset($result->headers['last-modified']) ? strtotime($result->headers['last-modified']) : 0;
264
    }
265
    return $result;
266
  }
267
  else {
268
    switch ($result->code) {
269
      case 404:
270
        // File not found occurs when a translation file is not yet available
271
        // at the translation server. But also if a custom module or custom
272
        // theme does not define the location of a translation file. By default
273
        // the file is checked at the translation server, but it will not be
274
        // found there.
275
        watchdog('l10n_update', 'File not found: @uri.', array('@uri' => $url));
276
        return TRUE;
277
      case 0:
278
        watchdog('l10n_update', 'Error occurred when trying to check @remote: @errormessage.', array('@errormessage' => $result->error, '@remote' => $url), WATCHDOG_ERROR);
279
        break;
280
      default:
281
        watchdog('l10n_update', 'HTTP error @errorcode occurred when trying to check @remote.', array('@errorcode' => $result->code, '@remote' => $url), WATCHDOG_ERROR);
282
        break;
283
    }
263 284
  }
264 285
  return $result;
265 286
}
......
297 318
 *     received.
298 319
 *   - redirect_code: If redirected, an integer containing the initial response
299 320
 *     status code.
300
 *   - redirect_url: If redirected, a string containing the redirection location.
321
 *   - redirect_url: If redirected, a string containing the URL of the redirect
322
 *     target.
301 323
 *   - error: If an error occurred, the error message. Otherwise not set.
302 324
 *   - headers: An array containing the response headers as name/value pairs.
303 325
 *     HTTP header names are case-insensitive (RFC 2616, section 4.2), so for
......
333 355
    'timeout' => 30.0,
334 356
    'context' => NULL,
335 357
  );
358

  
359
  // Merge the default headers.
360
  $options['headers'] += array(
361
    'User-Agent' => 'Drupal (+http://drupal.org/)',
362
  );
363

  
336 364
  // stream_socket_client() requires timeout to be a float.
337 365
  $options['timeout'] = (float) $options['timeout'];
338 366

  
367
  // Use a proxy if one is defined and the host is not on the excluded list.
368
  $proxy_server = variable_get('proxy_server', '');
369
  if ($proxy_server && _drupal_http_use_proxy($uri['host'])) {
370
    // Set the scheme so we open a socket to the proxy server.
371
    $uri['scheme'] = 'proxy';
372
    // Set the path to be the full URL.
373
    $uri['path'] = $url;
374
    // Since the URL is passed as the path, we won't use the parsed query.
375
    unset($uri['query']);
376

  
377
    // Add in username and password to Proxy-Authorization header if needed.
378
    if ($proxy_username = variable_get('proxy_username', '')) {
379
      $proxy_password = variable_get('proxy_password', '');
380
      $options['headers']['Proxy-Authorization'] = 'Basic ' . base64_encode($proxy_username . (!empty($proxy_password) ? ":" . $proxy_password : ''));
381
    }
382
    // Some proxies reject requests with any User-Agent headers, while others
383
    // require a specific one.
384
    $proxy_user_agent = variable_get('proxy_user_agent', '');
385
    // The default value matches neither condition.
386
    if ($proxy_user_agent === NULL) {
387
      unset($options['headers']['User-Agent']);
388
    }
389
    elseif ($proxy_user_agent) {
390
      $options['headers']['User-Agent'] = $proxy_user_agent;
391
    }
392
  }
393

  
339 394
  switch ($uri['scheme']) {
395
    case 'proxy':
396
      // Make the socket connection to a proxy server.
397
      $socket = 'tcp://' . $proxy_server . ':' . variable_get('proxy_port', 8080);
398
      // The Host header still needs to match the real request.
399
      $options['headers']['Host'] = $uri['host'];
400
      $options['headers']['Host'] .= isset($uri['port']) && $uri['port'] != 80 ? ':' . $uri['port'] : '';
401
      break;
402

  
340 403
    case 'http':
341 404
    case 'feed':
342 405
      $port = isset($uri['port']) ? $uri['port'] : 80;
......
346 409
      // checking the host that do not take into account the port number.
347 410
      $options['headers']['Host'] = $uri['host'] . ($port != 80 ? ':' . $port : '');
348 411
      break;
412

  
349 413
    case 'https':
350 414
      // Note: Only works when PHP is compiled with OpenSSL support.
351 415
      $port = isset($uri['port']) ? $uri['port'] : 443;
352 416
      $socket = 'ssl://' . $uri['host'] . ':' . $port;
353 417
      $options['headers']['Host'] = $uri['host'] . ($port != 443 ? ':' . $port : '');
354 418
      break;
419

  
355 420
    default:
356 421
      $result->error = 'invalid schema ' . $uri['scheme'];
357 422
      $result->code = -1003;
......
376 441
    // Mark that this request failed. This will trigger a check of the web
377 442
    // server's ability to make outgoing HTTP requests the next time that
378 443
    // requirements checking is performed.
379
    // See system_requirements()
444
    // See system_requirements().
380 445
    // variable_set('drupal_http_request_fails', TRUE);
381 446

  
382 447
    return $result;
......
388 453
    $path .= '?' . $uri['query'];
389 454
  }
390 455

  
391
  // Merge the default headers.
392
  $options['headers'] += array(
393
    'User-Agent' => 'Drupal (+http://drupal.org/)',
394
  );
395

  
396 456
  // Only add Content-Length if we actually have any content or if it is a POST
397 457
  // or PUT request. Some non-standard servers get confused by Content-Length in
398 458
  // at least HEAD/GET requests, and Squid always requires Content-Length in
......
404 464

  
405 465
  // If the server URL has a user then attempt to use basic authentication.
406 466
  if (isset($uri['user'])) {
407
    $options['headers']['Authorization'] = 'Basic ' . base64_encode($uri['user'] . (!empty($uri['pass']) ? ":" . $uri['pass'] : ''));
467
    $options['headers']['Authorization'] = 'Basic ' . base64_encode($uri['user'] . (isset($uri['pass']) ? ':' . $uri['pass'] : ''));
408 468
  }
409 469

  
410 470
  // If the database prefix is being used by SimpleTest to run the tests in a copied
......
459 519
    return $result;
460 520
  }
461 521
  // Parse response headers from the response body.
462
  list($response, $result->data) = explode("\r\n\r\n", $response, 2);
522
  // Be tolerant of malformed HTTP responses that separate header and body with
523
  // \n\n or \r\r instead of \r\n\r\n.
524
  list($response, $result->data) = preg_split("/\r\n\r\n|\n\n|\r\r/", $response, 2);
463 525
  $response = preg_split("/\r\n|\n|\r/", $response);
464 526

  
465 527
  // Parse the response status line.
......
551 613
        $result = l10n_update_http_request($location, $options);
552 614
        $result->redirect_code = $code;
553 615
      }
554
      $result->redirect_url = $location;
616
      if (!isset($result->redirect_url)) {
617
        $result->redirect_url = $location;
618
      }
555 619
      break;
556 620
    default:
557 621
      $result->error = $status_message;

Formats disponibles : Unified diff