function handleResult(WebResponse $response) { if ($this->contentType) { $response->addHeader('Content-Type', $this->contentType); } $fileSize = filesize($this->filepath); $creation = date(DateTime::RFC822, filectime($this->filepath)); $modif = date(DateTime::RFC822, filemtime($this->filepath)); $response->addHeader('Content-Disposition', "attachment; filename=\"{$this->filename}\"; size={$fileSize}; creation-date={$creation}; modification-date={$modif}"); $response->writeFile($this->filepath)->finish(); }
/** * 获取请求的响应 * @public * @return <WebResponse> http请求的响应信息 */ public function getResponse() { if (!($fp = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout))) { switch ($errno) { case -3: $this->errormsg = 'Socket连接创建失败 (-3)'; break; case -4: $this->errormsg = 'DNS定位失败 (-4)'; break; case -5: $this->errormsg = '连接超时或被拒绝 (-5)'; break; default: $this->errormsg = '连接失败 (' . $errno . ')'; break; $this->errormsg .= ' ' . $errstr; } return false; } else { } socket_set_timeout($fp, $this->timeout); $request = $this->buildRequestInfo(); fwrite($fp, $request); $content = ''; $readState = 'start'; $response = new WebResponse(); while (!feof($fp)) { $line = fgets($fp, 4096); if ($readState == 'start') { $readState = 'header'; if (!preg_match('/HTTP\\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) { $this->errormsg = "非法的请求状态: " . htmlentities($line); return false; } $http_version = $m[1]; //未使用 $response->setStatus($m[2]); $status_string = $m[3]; //未使用 } else { if ($readState == 'header') { if (trim($line) == '') { $readState = 'content'; } if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) { continue; } $key = strtolower(trim($m[1])); $val = trim($m[2]); $response->appendHeader($key, $val); } else { $content .= $line; } } } fclose($fp); $response->setContent($content); return $response; }
function wfTokenAlways() { global $wgUser, $wgRequest; if ($wgUser->isLoggedIn() && !$wgRequest->getCookie('Token')) { $token = $wgUser->getToken(true); WebResponse::setcookie('Token', $token); } }
/** * Add response headers with debug data and statistics * * @param WebResponse $response * @author macbre */ private static function addExtraHeaders(WebResponse $response) { global $wgRequestTime; $elapsed = microtime(true) - $wgRequestTime; $response->header(sprintf('X-Served-By:%s', wfHostname())); $response->header(sprintf('X-Backend-Response-Time:%01.3f', $elapsed)); $response->header('X-Cache: ORIGIN'); $response->header('X-Cache-Hits: ORIGIN'); }
/** * deliver the response to the browser * * @param WebResponse $response the response object * * @return void */ protected function handleWebResponse(WebResponse $response) { $content = $response->prepare($this->request)->getContent(); if (!$this->isDev && $this->request->getMethod() == 'GET') { $this->writeCacheFile($content); } $response->send(); }
/** * @covers aRvi\WebResponse\WebResponse::setPayload */ public function testSetPayloadWithCasting() { $this->assertNull($this->object->setPayload(123)); $this->assertInternalType("string", $this->object->strPayload); $this->assertEquals("123", $this->object->strPayload); }
function handleResult(WebResponse $response) { $response->write($this->content)->finish(); }
function handleResult(WebResponse $response) { $response->redirect($this->url, $this->status)->finish(); }
/** * Set JSON payload * * @param mixed $mixedPayload Payload */ public function setPayload($mixedPayload) { parent::setPayload(json_encode($mixedPayload)); }
function handleResult(WebResponse $response) { $result = $this->view->render(); $response->write($result)->finish(); }
/** * Set JSONP payload * * @param mixed $mixedPayload Payload */ public function setPayload($mixedPayload) { parent::setPayload($this->strCallbackName . "(" . json_encode($mixedPayload) . ");"); }