Subversion Repositories Applications.annuaire

Rev

Rev 42 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42 aurelien 1
<?php
2
 
3
/**
4
 * This module contains the HTTP fetcher interface
5
 *
6
 * PHP versions 4 and 5
7
 *
8
 * LICENSE: See the COPYING file included in this distribution.
9
 *
10
 * @package Yadis
11
 * @author JanRain, Inc. <openid@janrain.com>
12
 * @copyright 2005 Janrain, Inc.
13
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
14
 */
15
 
16
class Services_Yadis_HTTPResponse {
17
    function Services_Yadis_HTTPResponse($final_url = null, $status = null,
18
                                         $headers = null, $body = null)
19
    {
20
        $this->final_url = $final_url;
21
        $this->status = $status;
22
        $this->headers = $headers;
23
        $this->body = $body;
24
    }
25
}
26
 
27
/**
28
 * This class is the interface for HTTP fetchers the Yadis library
29
 * uses.  This interface is only important if you need to write a new
30
 * fetcher for some reason.
31
 *
32
 * @access private
33
 * @package Yadis
34
 */
35
class Services_Yadis_HTTPFetcher {
36
 
37
    var $timeout = 20; // timeout in seconds.
38
 
39
    /**
40
     * Return whether a URL should be allowed. Override this method to
41
     * conform to your local policy.
42
     *
43
     * By default, will attempt to fetch any http or https URL.
44
     */
45
    function allowedURL($url)
46
    {
47
        return $this->URLHasAllowedScheme($url);
48
    }
49
 
50
    /**
51
     * Is this an http or https URL?
52
     *
53
     * @access private
54
     */
55
    function URLHasAllowedScheme($url)
56
    {
57
        return (bool)preg_match('/^https?:\/\//i', $url);
58
    }
59
 
60
    /**
61
     * @access private
62
     */
63
    function _findRedirect($headers)
64
    {
65
        foreach ($headers as $line) {
66
            if (strpos($line, "Location: ") === 0) {
67
                $parts = explode(" ", $line, 2);
68
                return $parts[1];
69
            }
70
        }
71
        return null;
72
    }
73
 
74
    /**
75
     * Fetches the specified URL using optional extra headers and
76
     * returns the server's response.
77
     *
78
     * @param string $url The URL to be fetched.
79
     * @param array $extra_headers An array of header strings
80
     * (e.g. "Accept: text/html").
81
     * @return mixed $result An array of ($code, $url, $headers,
82
     * $body) if the URL could be fetched; null if the URL does not
83
     * pass the URLHasAllowedScheme check or if the server's response
84
     * is malformed.
85
     */
86
    function get($url, $headers)
87
    {
88
        trigger_error("not implemented", E_USER_ERROR);
89
    }
90
}
91
 
92
?>