You are here

function _emfield_http_request_header in Embedded Media Field 5

Same name and namespace in other branches
  1. 6.3 deprecated/emfield-deprecated.inc \_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 ./emfield.module
Get the HTTP Header of media, for mime-type and length

File

./emfield.module, line 842

Code

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

    // the intention here 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) {
        $result = _emfield_http_request_header($result->headers['Location'], --$retry);
        $result->redirect_code = $result->code;
      }
      $result->redirect_url = $location;
      break;
    default:
  }
  return $result;
}