X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2F3rdparty%2Fhumble-http-agent%2FSimplePie_HumbleHttpAgent.php;fp=inc%2F3rdparty%2Fhumble-http-agent%2FSimplePie_HumbleHttpAgent.php;h=ce76a929f90d4ca60f235fcb61fb356d4f514eae;hb=ec3972361d95f6f5956df77f7a76105b5ae6af72;hp=0000000000000000000000000000000000000000;hpb=fccd59e2e303cdbb45293365bf92921b831bf140;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/3rdparty/humble-http-agent/SimplePie_HumbleHttpAgent.php b/inc/3rdparty/humble-http-agent/SimplePie_HumbleHttpAgent.php new file mode 100644 index 00000000..ce76a929 --- /dev/null +++ b/inc/3rdparty/humble-http-agent/SimplePie_HumbleHttpAgent.php @@ -0,0 +1,79 @@ +encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']); + } + $this->url = $url; + $this->useragent = $useragent; + if (preg_match('/^http(s)?:\/\//i', $url)) + { + if (!is_array($headers)) + { + $headers = array(); + } + $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL; + $headers2 = array(); + foreach ($headers as $key => $value) { + $headers2[] = "$key: $value"; + } + //TODO: allow for HTTP headers + // curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2); + + $response = self::$agent->get($url); + + if ($response === false || !isset($response['status_code'])) { + $this->error = 'failed to fetch URL'; + $this->success = false; + } else { + // The extra lines at the end are there to satisfy SimplePie's HTTP parser. + // The class expects a full HTTP message, whereas we're giving it only + // headers - the new lines indicate the start of the body. + $parser = new SimplePie_HTTP_Parser($response['headers']."\r\n\r\n"); + if ($parser->parse()) { + $this->headers = $parser->headers; + //$this->body = $parser->body; + $this->body = $response['body']; + $this->status_code = $parser->status_code; + } + } + } + else + { + $this->error = 'invalid URL'; + $this->success = false; + } + } +} +?> \ No newline at end of file