3 * Implementation of discovery using HTTP Link header
5 * Discovers XRD file for a user by fetching the URL and reading any
6 * Link: headers in the HTTP response.
10 * @author James Walker <james@status.net>
11 * @copyright 2010 StatusNet, Inc.
12 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
13 * @link http://status.net/
15 class LRDDMethod_LinkHeader extends LRDDMethod
18 * For HTTP IDs fetch the URL and look for Link headers.
20 * @todo fail out of WebFinger URIs faster
22 public function discover($uri)
24 $response = self::fetchUrl($uri, HTTPClient::METHOD_HEAD);
26 $link_header = $response->getHeader('Link');
27 if (empty($link_header)) {
28 throw new Exception('No Link header found');
30 common_debug('LRDD LinkHeader found: '.var_export($link_header,true));
32 return self::parseHeader($link_header);
36 * Given a string or array of headers, returns JRD-like assoc array
38 * @param string|array $header string or array of strings for headers
40 * @return array of associative arrays in JRD-like array format
42 protected static function parseHeader($header)
44 $lh = new LinkHeader($header);
46 $link = new XML_XRD_Element_Link($lh->rel, $lh->href, $lh->type);