Psr7Middlewares\Middleware\EncodingNegotiator::getEncoding PHP Method

getEncoding() public static method

Returns the encoding.
public static getEncoding ( Psr\Http\Message\ServerRequestInterface $request ) : string | null
$request Psr\Http\Message\ServerRequestInterface
return string | null
    public static function getEncoding(ServerRequestInterface $request)
    {
        return self::getAttribute($request, self::KEY);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Execute the middleware.
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @param callable               $next
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     //If basePath does not match
     if (!$this->testBasePath($request->getUri()->getPath())) {
         return $next($request, $response);
     }
     //If the method is not allowed
     if ($request->getMethod() !== 'GET') {
         return $response->withStatus(405);
     }
     $body = Middleware::createStream();
     $file = $this->getFilename($request);
     //If the file does not exists, check if is gzipped
     if (!is_file($file)) {
         $file .= '.gz';
         if (EncodingNegotiator::getEncoding($request) !== 'gzip' || !is_file($file)) {
             return $response->withStatus(404);
         }
         $response = $response->withHeader('Content-Encoding', 'gzip');
     }
     self::readFile($file, $body);
     $response = $response->withBody($body);
     //Handle range header
     $response = $this->range($request, $response);
     return $next($request, $response);
 }
All Usage Examples Of Psr7Middlewares\Middleware\EncodingNegotiator::getEncoding