1 | <?php |
||
17 | class HttpGetRequest |
||
18 | { |
||
19 | public $origin; |
||
20 | public $scheme = 'http'; |
||
21 | public $host = 'example.com'; |
||
22 | public $port = 80; |
||
23 | public $path = '/'; |
||
24 | |||
25 | public $query = array(); |
||
26 | public $headers = array(); |
||
27 | |||
28 | public $curlOpts = array(); |
||
29 | |||
30 | public $username = null; |
||
31 | public $password = null; |
||
32 | |||
33 | public $maybePublic = false; |
||
34 | public $verbose = false; |
||
35 | |||
36 | /** @internal */ |
||
37 | const TOKEN_LABEL = 'access_token'; |
||
38 | |||
39 | /** |
||
40 | * normalize url and authentication info |
||
41 | * @param string $origin domain text |
||
42 | * @param string $url |
||
43 | * @param IO\IOInterface $io |
||
44 | */ |
||
45 | 15 | public function __construct($origin, $url, IO\IOInterface $io) |
|
59 | |||
60 | 15 | private function setupProxy() |
|
|
|||
61 | { |
||
62 | // no_proxy skip |
||
63 | 15 | if (isset($_SERVER['no_proxy'])) { |
|
64 | 1 | $pattern = new NoProxyPattern($_SERVER['no_proxy']); |
|
65 | 1 | if ($pattern->test($this->getURL())) { |
|
66 | 1 | unset($this->curlOpts[CURLOPT_PROXY]); |
|
67 | 1 | return; |
|
68 | } |
||
69 | 1 | } |
|
70 | |||
71 | 15 | $httpProxy = self::issetOr($_SERVER, 'http_proxy', 'HTTP_PROXY'); |
|
72 | 15 | if ($httpProxy && $this->scheme === 'http') { |
|
73 | 1 | $this->curlOpts[CURLOPT_PROXY] = $httpProxy; |
|
74 | 1 | return; |
|
75 | } |
||
76 | |||
77 | 14 | $httpsProxy = self::issetOr($_SERVER, 'https_proxy', 'HTTPS_PROXY'); |
|
78 | 14 | if ($httpsProxy && $this->scheme === 'https') { |
|
79 | 1 | $this->curlOpts[CURLOPT_PROXY] = $httpsProxy; |
|
80 | 1 | return; |
|
81 | } |
||
82 | |||
83 | 13 | unset($this->curlOpts[CURLOPT_PROXY]); |
|
84 | 13 | unset($this->curlOpts[CURLOPT_PROXYUSERPWD]); |
|
85 | 13 | } |
|
86 | |||
87 | 15 | private static function issetOr(array $arr, $key1, $key2) |
|
97 | |||
98 | /** |
||
99 | * @param string $url |
||
100 | */ |
||
101 | 15 | public function importURL($url) |
|
121 | |||
122 | |||
123 | /** |
||
124 | * @param array $struct |
||
125 | * @param string $key |
||
126 | * @param string $default |
||
127 | * @return mixed |
||
128 | */ |
||
129 | 15 | private static function setOr(array $struct, $key, $default = null) |
|
137 | |||
138 | /** |
||
139 | * process option for RemortFileSystem |
||
140 | * @param array $options |
||
141 | * @return void |
||
142 | */ |
||
143 | 2 | public function processRFSOption(array $options) |
|
149 | |||
150 | /** |
||
151 | * @return array |
||
152 | */ |
||
153 | 4 | public function getCurlOpts() |
|
183 | |||
184 | /** |
||
185 | * enable ECC cipher suites in cURL/NSS |
||
186 | */ |
||
187 | 4 | public function nssCiphers() |
|
200 | |||
201 | 8 | public function getURL() |
|
221 | |||
222 | /** |
||
223 | * @return string |
||
224 | */ |
||
225 | 4 | public static function genUA() |
|
241 | } |
||
242 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: