protected function buildRawResponse($response, &$responseInfo) { $statusName = StupidHttp_WebServer::getHttpStatusHeader($response->getStatus()); $responseStr = "HTTP/1.1 " . $statusName . PHP_EOL; $responseStr .= "Server: StupidHttp" . PHP_EOL; $responseStr .= "Date: " . date("D, d M Y H:i:s T") . PHP_EOL; foreach ($response->getFormattedHeaders() as $header) { $responseStr .= $header . PHP_EOL; } $responseStr .= PHP_EOL; $responseInfo['header_length'] = strlen($responseStr); if ($response->getBody() != null) { $responseStr .= $response->getBody(); } return $responseStr; }
protected function logRequest($requestInfo) { // Get profiling info. $profiling = $requestInfo['profiling']; $receiveTime = $processTime = $sendTime = 0; if (isset($profiling['receive.start']) and isset($profiling['receive.end'])) { $receiveTime = ($profiling['receive.end'] - $profiling['receive.start']) * 1000.0; } if (isset($profiling['process.start']) and isset($profiling['process.end'])) { $processTime = ($profiling['process.end'] - $profiling['process.start']) * 1000.0; } if (isset($profiling['send.start']) and isset($profiling['send.end'])) { $sendTime = ($profiling['send.end'] - $profiling['send.start']) * 1000.0; } $totalTime = ceil($receiveTime + $processTime + $sendTime); // Do the logging. $request = $requestInfo['request']; $response = $requestInfo['response']; if ($request and $response) { $clientInfo = $this->handler->getClientInfo($requestInfo['socket']); $statusName = StupidHttp_WebServer::getHttpStatusHeader($response->getStatus()); $replacements = array('%date%' => date(self::REQUEST_DATE_FORMAT), '%client_ip%' => $clientInfo['address'], '%client_port%' => $clientInfo['port'], '%method%' => $request->getMethod(), '%uri%' => $request->getUri(), '%path%' => $request->getUriPath(), '%status%' => $response->getStatus(), '%status_name%' => $statusName, '%time%' => $totalTime); $this->log->info(str_replace(array_keys($replacements), array_values($replacements), self::REQUEST_LOG_FORMAT)); } }
/** * Logs a request. */ public function logRequest($request, $requestInfo, $response) { $statusName = StupidHttp_WebServer::getHttpStatusHeader($response->getStatus()); $replacements = array('%date%' => date($this->dateFormat), '%client_ip%' => $requestInfo['address'], '%client_port%' => $requestInfo['port'], '%method%' => $request->getMethod(), '%uri%' => $request->getUri(), '%path%' => $request->getUriPath(), '%status%' => $response->getStatus(), '%status_name%' => $statusName, '%time%' => $requestInfo['time']); $this->info(str_replace(array_keys($replacements), array_values($replacements), $this->requestFormat)); }