public function handle(RequestInterface $request, ResponseInterface $response, FilterChainInterface $filterChain) { $signature = null; if ($request->hasHeader('Cookie')) { $cookies = Cookie::parseList($request->getHeader('Cookie')); foreach ($cookies as $cookie) { if ($cookie->getName() == self::COOKIE_NAME) { $data = $cookie->getValue(); $parts = explode('.', $data, 2); $payload = isset($parts[0]) ? $parts[0] : null; $signature = isset($parts[1]) ? $parts[1] : null; if (strcmp($signature, $this->generateSignature($payload)) === 0) { $request->setAttribute(self::COOKIE_NAME, $this->unserializeData($payload)); } else { // invalid signature } break; } } } $filterChain->handle($request, $response); $data = $request->getAttribute(self::COOKIE_NAME); if (!empty($data)) { $payload = $this->serializeData($data); $newSignature = $this->generateSignature($payload); // send only a new cookie if the data has changed if ($newSignature != $signature) { $response->addHeader('Set-Cookie', self::COOKIE_NAME . '=' . $payload . '.' . $newSignature); } } }
public function handle(RequestInterface $request, ResponseInterface $response, FilterChainInterface $filterChain) { $authorization = $request->getHeader('Authorization'); if (!empty($authorization)) { $parts = explode(' ', $authorization, 2); $type = isset($parts[0]) ? $parts[0] : null; $data = isset($parts[1]) ? $parts[1] : null; if ($type == 'Basic' && !empty($data)) { $data = base64_decode($data); $parts = explode(':', $data, 2); $username = isset($parts[0]) ? $parts[0] : null; $password = isset($parts[1]) ? $parts[1] : null; $result = call_user_func_array($this->isValidCallback, array($username, $password)); if ($result === true) { $this->callSuccess($response); $filterChain->handle($request, $response); } else { $this->callFailure($response); } } else { $this->callMissing($response); } } else { $this->callMissing($response); } }
public function handle(RequestInterface $request, ResponseInterface $response, FilterChainInterface $filterChain) { $userAgent = $request->getHeader('User-Agent'); if (!empty($userAgent)) { $filterChain->handle($request, $response); } else { throw new BadRequestException('Request must contain an User-Agent header'); } }
/** * Returns the writer wich gets used if no writer was explicit selected * * @return \PSX\Data\WriterInterface */ private function getPreferredWriter() { $parameters = $this->request->getUri()->getParameters(); $format = isset($parameters['format']) ? $parameters['format'] : null; if (!empty($format)) { return $this->writerFactory->getWriterByFormat($format, $this->getSupportedWriter()); } else { return $this->writerFactory->getWriterByContentType($this->request->getHeader('Accept'), $this->getSupportedWriter()); } }
public function handle(RequestInterface $request, ResponseInterface $response, FilterChainInterface $filterChain) { $accept = $request->getHeader('Accept'); if (stripos($accept, 'text/html') !== false && is_file($this->file)) { $response->setHeader('Content-Type', 'text/html'); $response->getBody()->write(file_get_contents($this->file)); } else { $filterChain->handle($request, $response); } }
public function handle(RequestInterface $request, ResponseInterface $response, FilterChainInterface $filterChain) { $authorization = $request->getHeader('Authorization'); if (!empty($authorization)) { $parts = explode(' ', $authorization, 2); $type = isset($parts[0]) ? $parts[0] : null; $data = isset($parts[1]) ? $parts[1] : null; if ($type == 'OAuth' && !empty($data)) { $params = Authentication::decodeParameters($data); $params = array_map(array('\\PSX\\Oauth', 'urlDecode'), $params); // realm is not used in the base string unset($params['realm']); if (!isset($params['oauth_consumer_key'])) { throw new BadRequestException('Consumer key not set'); } if (!isset($params['oauth_token'])) { throw new BadRequestException('Token not set'); } if (!isset($params['oauth_signature_method'])) { throw new BadRequestException('Signature method not set'); } if (!isset($params['oauth_signature'])) { throw new BadRequestException('Signature not set'); } $consumer = call_user_func_array($this->consumerCallback, array($params['oauth_consumer_key'], $params['oauth_token'])); if ($consumer instanceof Consumer) { $signature = Oauth::getSignature($params['oauth_signature_method']); $method = $request->getMethod(); $url = $request->getUri(); $params = array_merge($params, $request->getUri()->getParameters()); if (strpos($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded') !== false) { $body = (string) $request->getBody(); $data = array(); parse_str($body, $data); $params = array_merge($params, $data); } $baseString = Oauth::buildBasestring($method, $url, $params); if ($signature->verify($baseString, $consumer->getConsumerSecret(), $consumer->getTokenSecret(), $params['oauth_signature']) !== false) { $this->callSuccess($response); $filterChain->handle($request, $response); } else { $this->callFailure($response); } } else { $this->callFailure($response); } } else { $this->callMissing($response); } } else { $this->callMissing($response); } }
public function handle(RequestInterface $request, ResponseInterface $response, FilterChainInterface $filterChain) { if ($request->hasHeader('Accept-Encoding')) { $acceptEncoding = $request->getHeader('Accept-Encoding'); if (strpos($acceptEncoding, 'gzip') !== false) { // the sender will compress the response if the content encoding // header is available $response->setHeader('Content-Encoding', 'gzip'); } } $filterChain->handle($request, $response); }
public function handle(RequestInterface $request, ResponseInterface $response, FilterChainInterface $filterChain) { $authorization = $request->getHeader('Authorization'); if (!empty($authorization)) { $parts = explode(' ', $authorization, 2); $type = isset($parts[0]) ? $parts[0] : null; $accessToken = isset($parts[1]) ? $parts[1] : null; if ($type == 'Bearer' && !empty($accessToken)) { $result = call_user_func_array($this->accessCallback, array($accessToken)); if ($result === true) { $this->callSuccess($response); $filterChain->handle($request, $response); } else { $this->callFailure($response); } } else { $this->callMissing($response); } } else { $this->callMissing($response); } }
public function log($appId, $routeId, $ip, RequestInterface $request) { $now = new \DateTime(); $this->connection->insert('fusio_log', array('appId' => $appId, 'routeId' => $routeId, 'ip' => $ip, 'userAgent' => $request->getHeader('User-Agent'), 'method' => $request->getMethod(), 'path' => $request->getRequestTarget(), 'header' => $this->getHeadersAsString($request), 'body' => $this->getBodyAsString($request), 'date' => $now->format('Y-m-d H:i:s'))); return $this->connection->lastInsertId(); }
public function handle(RequestInterface $request, ResponseInterface $response, FilterChainInterface $filterChain) { $authorization = $request->getHeader('Authorization'); if (!empty($authorization)) { $parts = explode(' ', $authorization, 2); $type = isset($parts[0]) ? $parts[0] : null; $data = isset($parts[1]) ? $parts[1] : null; if ($type == 'Digest' && !empty($data)) { $params = Authentication::decodeParameters($data); $algo = isset($params['algorithm']) ? $params['algorithm'] : 'MD5'; $qop = isset($params['qop']) ? $params['qop'] : 'auth'; if (!$this->digest instanceof Digest) { throw new BadRequestException('Digest not available'); } if ($this->digest->getOpaque() != $params['opaque']) { throw new BadRequestException('Invalid opaque'); } // build ha1 $ha1 = call_user_func_array($this->ha1Callback, array($params['username'])); if ($algo == 'MD5-sess') { $ha1 = md5($ha1 . ':' . $this->digest->getNonce() . ':' . $params['cnonce']); } // build ha2 if ($qop == 'auth-int') { $ha2 = md5($request->getMethod() . ':' . $request->getUri()->getPath() . ':' . md5($request->getBody())); } else { $ha2 = md5($request->getMethod() . ':' . $request->getUri()->getPath()); } // build response if ($qop == 'auth' || $qop == 'auth-int') { $hash = md5($ha1 . ':' . $this->digest->getNonce() . ':' . $params['nc'] . ':' . $params['cnonce'] . ':' . $qop . ':' . $ha2); } else { $hash = md5($ha1 . ':' . $this->digest->getNonce() . ':' . $ha2); } if (strcmp($hash, $params['response']) === 0) { $this->callSuccess($response, $hash); $filterChain->handle($request, $response); } else { $this->callFailure($response); } } else { $this->callMissing($response); } } else { $this->callMissing($response); } }
/** * @param string $name * @return null|string */ public function getHeader($name) { return $this->request->getHeader($name); }