public function testSetHeaders() { $request = new Request('http://google.com', 'GET'); $request->setHeaders(array('foo' => 'bar'), true); $this->assertEquals(array('foo' => 'bar'), $request->getRawHeaders(), 'Set headers failed'); $request->setHeaders(array('foo' => 'bar2'), true); $this->assertEquals(array('foo' => 'bar2'), $request->getRawHeaders(), 'Overwrite headers failed'); $request->setHeaders(array('foo2' => 'bar'), true); $this->assertEquals(array('foo' => 'bar2', 'foo2' => 'bar'), $request->getRawHeaders(), 'Set second headers failed'); $request->setHeaders(array('bla' => 'blub')); $this->assertEquals(array('bla' => 'blub'), $request->getRawHeaders(), 'Reset headers failed'); }
/** * Redirects the browser to a page specified by the $url argument. * * <code> * Request::redirect('test'); * </code> * * @param string $url The URL * @param integer $status Status * @param integer $delay Delay */ public static function redirect($url, $status = 302, $delay = null) { // Redefine vars $url = (string) $url; $status = (int) $status; // Status codes $messages = array(); $messages[301] = '301 Moved Permanently'; $messages[302] = '302 Found'; // Is Headers sent ? if (headers_sent()) { echo "<script>document.location.href='" . $url . "';</script>\n"; } else { // Redirect headers Request::setHeaders('HTTP/1.1 ' . $status . ' ' . Arr::get($messages, $status, 302)); // Delay execution if ($delay !== null) { sleep((int) $delay); } // Redirect Request::setHeaders("Location: {$url}"); // Shutdown request Request::shutdown(); } }
/** * @param Request $request * * @return Request */ public function beforeSend(Request $request) { //Host API isn't restful so path must always self::ENDPOINT_PATH $request->setUrl(self::ENDPOINT_PATH); $headers = array(self::CF_INTEGRATION_HEADER => $this->config->getValue('integrationName'), self::CF_INTEGRTATION_VERSION_HEADER => $this->config->getValue('version')); $request->setHeaders($headers); $body = $request->getBody(); $user_key_actions = array('zone_set', 'full_zone_set'); if (in_array(strtolower($body['act']), $user_key_actions)) { $body['user_key'] = $this->data_store->getHostAPIUserKey(); } $body['host_key'] = $this->integrationAPI->getHostAPIKey(); $request->setBody($body); return $request; }
* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /* * fn: Action::run('Api') * Page/File: api/api.md * Template: api.tpl * Link blog: api?action=blog * link by page:api?action=contact */ Action::add('Api', function () { //print_r(json_encode(Config::getConfig(),true)); if (Request::get('type')) { cors(); Request::setHeaders('Content-Type: application/json; charset=' . Config::get('system.charset')); $result = ''; switch (Request::get('type')) { case 'page': // api?type=page&name=blog/hello get all if (Request::get('name')) { // get page name $p = @Pages::getPage(Request::get('name')); $title = isset($p['title']) ? $p['title'] : ''; $date = isset($p['date']) ? $p['date'] : ''; $slug = isset($p['slug']) ? $p['slug'] : ''; $url = isset($p['url']) ? $p['url'] : ''; $tag = isset($p['tag']) ? $p['tag'] : ''; $thumbnail = isset($p['thumbnail']) ? $p['thumbnail'] : ''; $template = isset($p['template']) ? $p['template'] : ''; $summary = isset($p['summary']) ? $p['summary'] : '';
<?php /** * Morfy Feed Plugin * * (c) Romanenko Sergey / Awilum <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ if (Url::getUriSegment(0) == 'rss') { Morfy::factory()->addAction('before_render', function () { $fenom = Fenom::factory(PLUGINS_PATH . '/feed/templates/', CACHE_PATH . '/fenom/', Morfy::$fenom); $fenom->setOptions(array("strip" => false)); Response::status(200); Request::setHeaders('Content-Type: text/xml; charset=utf-8'); $fenom->display('rss.tpl', array('page' => Morfy::factory()->getPage(Morfy::$plugins['feed']['page']), 'pages' => Morfy::factory()->getPages(Morfy::$plugins['feed']['page'], 'date', 'DESC', array('404')))); Request::shutdown(); }); }
/** * Create new Request and add it to the request queue * * @param string $url * @param string $method * @param array|string $postData * @param array $headers * @param array $options * @return RollingCurl */ public function request($url, $method = "GET", $postData = null, $headers = null, $options = null) { $newRequest = new Request($url, $method); if ($postData) { $newRequest->setPostData($postData); } if ($headers) { $newRequest->setHeaders($headers); } if ($options) { $newRequest->setOptions($options); } return $this->add($newRequest); }