gzipEnabled = \extension_loaded('zlib'); } public function get($url, $headers = []) { return $this->request('GET', $url, $headers); } public function post($url, $headers = [], $body = '') { return $this->request('POST', $url, $headers, $body); } protected function createContext($method, array $headers, $body) { $contextOptions = [ 'ssl' => ['verify_peer' => $this->sslVerifyPeer], 'http' => [ 'method' => $method, 'timeout' => $this->timeout, 'header' => $this->generateHeaders($headers, $body), 'content' => $body ] ]; return \stream_context_create($contextOptions); } protected function decompress($content) { if ($this->gzipEnabled && \substr($content, 0, 2) === "\x1f\x8b") return \gzdecode($content); return $content; } protected function generateHeaders(array $headers, $body) { if ($this->gzipEnabled) $headers[] = 'Accept-Encoding: gzip'; $headers[] = 'Content-Length: ' . \strlen($body); return $headers; } protected function request($method, $url, $headers, $body = '') { $response = @\file_get_contents($url, \false, $this->createContext($method, $headers, $body)); return (\is_string($response)) ? $this->decompress($response) : $response; } }