+ if(strpos($short_url,'://') === false){
+ return $short_url;
+ }
+ try {
+ $request = self::_commonHttp($short_url, $redirs);
+ // Don't include body in output
+ $request->setMethod(HTTP_Request2::METHOD_HEAD);
+ $response = $request->send();
+
+ if (405 == $response->getStatus()) {
+ // Server doesn't support HEAD method? Can this really happen?
+ // We'll try again as a GET and ignore the response data.
+ $request = self::_commonHttp($short_url, $redirs);
+ $response = $request->send();
+ }
+ } catch (Exception $e) {
+ // Invalid URL or failure to reach server
+ common_log(LOG_ERR, "Error while following redirects for $short_url: " . $e->getMessage());
+ return $short_url;
+ }
+
+ if ($response->getRedirectCount() && File::isProtected($response->getUrl())) {
+ // Bump back up the redirect chain until we find a non-protected URL
+ return self::lookupWhere($short_url, $response->getRedirectCount() - 1, true);
+ }
+
+ $ret = array('code' => $response->getStatus()
+ , 'redirects' => $response->getRedirectCount()
+ , 'url' => $response->getUrl());
+
+ $type = $response->getHeader('Content-Type');
+ if ($type) $ret['type'] = $type;
+ if ($protected) $ret['protected'] = true;
+ $size = $response->getHeader('Content-Length'); // @fixme bytes?
+ if ($size) $ret['size'] = $size;
+ $time = $response->getHeader('Last-Modified');
+ if ($time) $ret['time'] = strtotime($time);
+ return $ret;
+ }
+
+ /**
+ * Check if this URL is a redirect and return redir info.
+ * If a File record is present for this URL, it is not considered a redirect.
+ * If a File_redirection record is present for this URL, the recorded target is returned.
+ *
+ * If no File or File_redirect record is present, the URL is hit and any
+ * redirects are followed, up to 10 levels or until a protected URL is
+ * reached.
+ *
+ * @param string $in_url
+ * @return mixed one of:
+ * string - target URL, if this is a direct link or a known redirect
+ * array - redirect info if this is an *unknown* redirect:
+ * associative array with the following elements:
+ * code: HTTP status code
+ * redirects: count of redirects followed
+ * url: URL string of final target
+ * type (optional): MIME type from Content-Type header
+ * size (optional): byte size from Content-Length header
+ * time (optional): timestamp from Last-Modified header
+ */
+ public function where($in_url) {