xref: /dokuwiki/inc/HTTP/DokuHTTPClient.php (revision 7d34963b3e75ea04c63ec066a6b7a692e123cb53)
1<?php
2
3
4namespace dokuwiki\HTTP;
5
6use dokuwiki\Extension\Event;
7/**
8 * Adds DokuWiki specific configs to the HTTP client
9 *
10 * @author Andreas Goetz <cpuidle@gmx.de>
11 * @link https://www.dokuwiki.org/devel:httpclient
12 */
13class DokuHTTPClient extends HTTPClient
14{
15
16    /**
17     * Constructor.
18     *
19     * @author Andreas Gohr <andi@splitbrain.org>
20     */
21    public function __construct()
22    {
23        global $conf;
24
25        // call parent constructor
26        parent::__construct();
27
28        // set some values from the config
29        $this->proxy_host = $conf['proxy']['host'];
30        $this->proxy_port = $conf['proxy']['port'];
31        $this->proxy_user = $conf['proxy']['user'];
32        $this->proxy_pass = conf_decodeString($conf['proxy']['pass']);
33        $this->proxy_ssl = $conf['proxy']['ssl'];
34        $this->proxy_except = $conf['proxy']['except'];
35
36        // allow enabling debugging via URL parameter (if debugging allowed)
37        if ($conf['allowdebug']) {
38            if (
39                isset($_REQUEST['httpdebug']) ||
40                (
41                    isset($_SERVER['HTTP_REFERER']) &&
42                    strpos($_SERVER['HTTP_REFERER'], 'httpdebug') !== false
43                )
44            ) {
45                $this->debug = true;
46            }
47        }
48    }
49
50
51    /**
52     * Wraps an event around the parent function
53     *
54     * @triggers HTTPCLIENT_REQUEST_SEND
55     * @author   Andreas Gohr <andi@splitbrain.org>
56     */
57    /**
58     * @param string $url
59     * @param string|array $data the post data either as array or raw data
60     * @param string $method
61     * @return bool
62     */
63    public function sendRequest($url, $data = '', $method = 'GET')
64    {
65        $httpdata = [
66            'url' => $url,
67            'data' => $data,
68            'method' => $method
69        ];
70        $evt = new Event('HTTPCLIENT_REQUEST_SEND', $httpdata);
71        if ($evt->advise_before()) {
72            $url = $httpdata['url'];
73            $data = $httpdata['data'];
74            $method = $httpdata['method'];
75        }
76        $evt->advise_after();
77        unset($evt);
78        return parent::sendRequest($url, $data, $method);
79    }
80}
81