You are here

function _emfield_http_request_header in Embedded Media Field 6.3

Same name and namespace in other branches
  1. 5 emfield.module \_emfield_http_request_header()
  2. 6 emfield.module \_emfield_http_request_header()
  3. 6.2 emfield.module \_emfield_http_request_header()

HTTP HEAD - just request the header.

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

File

deprecated/emfield-deprecated.inc, line 466
Functionality to be deprecated from earlier versions of Embedded Media Field.

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;
}