You are here

function _emfield_http_request_header in Embedded Media Field 6.2

Same name and namespace in other branches
  1. 5 emfield.module \_emfield_http_request_header()
  2. 6.3 deprecated/emfield-deprecated.inc \_emfield_http_request_header()
  3. 6 emfield.module \_emfield_http_request_header()

HTTP HEAD - just request the header.

1 call to _emfield_http_request_header()
emfield_request_header in ./emfield.module
Get the HTTP Header of media, for mime-type and length.

File

./emfield.module, line 515
Embedded Media Field is a CCK-based framework for 3rd party media files.

Code

function _emfield_http_request_header($url, $retry = 4) {
  $result = drupal_http_request($url, array(), 'HEAD', NULL, 0);
  switch ($result->code) {

    // The intention is to retry if the correct information isn't available;
    // so far it's just tuned for YouTube. It's possible/probable that Moved
    // Temporarily will give the headers required elsewhere, and it maybe best
    // to test on the content of the header.
    case 200:

    // OK
    case 304:

      // Not modified - this shouldn't happen here.
      break;
    case 301:

    // Moved permanently.
    case 302:

    // Moved temporarily.
    case 303:

    // See Other <-- drupal_http_request doesn't deal with this; we
    // need this for YouTube.
    case 307:

      // Moved temporarily.
      $location = $result->headers['Location'];
      if ($retry > 0) {
        $result = _emfield_http_request_header($result->headers['Location'], --$retry);
        $result->redirect_code = $result->code;
      }
      $result->redirect_url = $location;
      break;
    default:
  }
  return $result;
}