/** * Executes a request * * @param \Duality\Structure\Http\Request &$request Give the HTTP request * * @return \Duality\Structure\Http\Response The resulting HTTP response */ public function execute(Request &$request) { $this->init(); $header = array(); $reqHeaders = $request->getHeaders(); if (empty($reqHeaders)) { $header[] = "Accept: text/html,application/xhtml+xml,application/xml;" . "q=0.9,*/*;q=0.8"; $header[] = "Cache-Control: max-age=0"; $header[] = "Connection: keep-alive"; $header[] = "Keep-Alive: timeout=5, max=100"; $header[] = "Accept-Charset: utf-8,ISO-8859-1;q=0.7,*;q=0.3"; $header[] = "Accept-Language: en-US,en;q=0.8"; $header[] = "Pragma: "; } else { foreach ($request->getHeaders() as $key => $item) { $header[] = $key . ': ' . $item; } } curl_setopt($this->curl, CURLOPT_URL, $request->getUrl()); curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->curl, CURLOPT_USERAGENT, $this->getUserAgent()); curl_setopt($this->curl, CURLOPT_HTTPHEADER, $header); curl_setopt($this->curl, CURLOPT_REFERER, 'http://localhost'); curl_setopt($this->curl, CURLOPT_ENCODING, 'gzip,deflate,sdch'); curl_setopt($this->curl, CURLOPT_AUTOREFERER, true); curl_setopt($this->curl, CURLOPT_TIMEOUT, 3); curl_setopt($this->curl, CURLOPT_HEADER, 1); $result = curl_exec($this->curl); $this->response = $this->parseResult($result); curl_close($this->curl); return $this->response; }
/** * Test HTTP */ public function testHTTP() { $request = new \Duality\Structure\Http\Request(new \Duality\Structure\Url('http://localhost/dummy')); $request->setParams(array('key' => 'value')); $request->setMethod('GET'); $request->getHeaders(); $request->getHeaderItem('Content-Type'); $response = new \Duality\Structure\Http\Response(); $response->setUrl(new \Duality\Structure\Url('http://localhost/dummy')); $response->getUrl(); $response->setMethod('GET'); $response->getMethod(); $response->setStatus(200); $response->getStatus(); $response->setHeaders(array('Content-Type' => 'text/html')); $response->getHeaders(); $response->addHeader('Content-Type', 'text/html'); $cookie = array(); $cookie['name'] = 'duality'; $cookie['value'] = 'dummy'; $cookie['expire'] = 0; $cookie['path'] = '/'; $cookie['domain'] = 'domain.com'; $cookie['secure'] = false; $response->setCookies(array($cookie)); $response->getCookies(); $response->setContent('dummy'); $response->getContent(); $response->setTimestamp(time()); $response->getTimestamp(); $response->setAjax(true); $response->isAjax(); }