コード例 #1
0
ファイル: SocketAdapter.php プロジェクト: GeneralCrime/code
 public function executeRequest(Request $request)
 {
     // create request
     // 80 is the port of the web server
     $connection = fsockopen($request->getHost(), 80);
     $requestString = $this->getRequestStringRepresentation($request);
     fwrite($connection, $requestString);
     // get response
     // first line == status line
     $result = '';
     $statusLine = '';
     while ($line = fgets($connection)) {
         if (empty($statusLine)) {
             $statusLine = $line;
             continue;
         }
         $result .= $line;
     }
     // close connection
     fclose($connection);
     // split result into header and content
     // the header ends with \r\n\r\n
     $this->response = new ResponseImpl();
     $this->setHeadersFromString($this->response, $this->getHeadersString($result));
     $this->response->setBody($this->getBodyString($result));
     // parse status line
     // status-line-pattern: <HTTP-Version> <status-code> <reason-phrase>
     $status = explode(' ', $statusLine);
     $this->response->setVersion($status[0]);
     $this->response->setStatusCode($status[1]);
     $this->response->setReasonPhrase($status[2]);
     return $this->response;
 }
コード例 #2
0
ファイル: CUrlAdapter.php プロジェクト: GeneralCrime/code
 public function executeRequest(Request $request)
 {
     $cH = curl_init($request->getUrl());
     curl_setopt($cH, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($cH, CURLOPT_HEADER, true);
     if ($request->getMethod() === Request::METHOD_POST) {
         curl_setopt($cH, CURLOPT_POST, true);
         curl_setopt($cH, CURLOPT_POSTFIELDS, http_build_query($request->getParameters()));
     }
     $result = curl_exec($cH);
     $this->response = new ResponseImpl();
     $this->response->setStatusCode(curl_getinfo($cH, CURLINFO_HTTP_CODE));
     $this->setHeadersFromString($this->response, $this->getHeadersString($result));
     $this->response->setBody($this->getBodyString($result));
     curl_close($cH);
     return $this->response;
 }
コード例 #3
0
 protected function addHeaders(ResponseImpl &$response, $clientCachePeriod, $mimeType)
 {
     // send gzip header if supported
     if ($this->gzipIsSupported()) {
         $response->setHeader(new HeaderImpl('Content-Encoding', 'gzip'));
     }
     // send headers for caching
     $response->setHeader(new HeaderImpl('Cache-Control', 'public; max-age=' . $clientCachePeriod));
     $modifiedDate = date('D, d M Y H:i:s \\G\\M\\T', time());
     $response->setHeader(new HeaderImpl('Last-Modified', $modifiedDate));
     $expiresDate = date('D, d M Y H:i:s \\G\\M\\T', time() + $clientCachePeriod);
     $response->setHeader(new HeaderImpl('Expires', $expiresDate));
     $response->setHeader(new HeaderImpl('Content-Type', $mimeType));
 }