public function __invoke(HttpResponse $response) { $start = microtime(true); (yield null); $duration = microtime(true) - $start; $response->setHeader('X-Request-Duration', $duration * 1000); }
public function __invoke(HttpRequest $request, HttpResponse $response) { $path = $this->path . substr($request->getUrl(), 1); $fn = $this->filter; if ($fn($path)) { $response->setContentEncoding(HttpResponse::GZIP); if (is_dir($path) && $this->hasIndex) { // serve the index of the specified path $fn = $this->index; $response->setContentType('text/html'); $response->setBody($fn($path)); } else { if (is_file($path)) { $response->setContentType($this->finfo->file($path, FILEINFO_MIME_TYPE)); $response->setBody(fopen($path, 'r')); } } } }
public function __invoke(HttpRequest $request, HttpResponse $response) { $origin = $request->getHeader('Origin'); if (!empty($origin)) { if (in_array($origin, $this->domains)) { $response->setHeader('Access-Control-Allow-Origin', $origin); if (!!$this->credentials) { $response->setHeader('Access-Control-Allow-Credentials', !!$this->credentials ? 'true' : 'false'); } if (!empty($this->methods)) { $response->setHeader('Access-Control-Allow-Methods', implode(', ', $this->methods)); } if (!empty($this->allowHeaders)) { $response->setHeader('Access-Control-Allow-Headers', implode(', ', $this->allowHeaders)); } if (!empty($this->exposeHeaders)) { $response->setHeader('Access-Control-Expose-Headers', implode(', ', $this->exposeHeaders)); } if (!empty($this->ttl)) { $response->setHeader('Access-Control-Max-Age', $this->ttl); } } } }