From 28a8443a5f05593445be330704e5ad31b62cb7d1 Mon Sep 17 00:00:00 2001 From: Mark Sonnabaum Date: Mon, 3 Jun 2013 09:39:44 -0500 Subject: [PATCH] [HttpFoundation] Added Request::getEncodings() method --- .../Component/HttpFoundation/Request.php | 17 +++++++++++++++++ .../HttpFoundation/Tests/RequestTest.php | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 756e4847d8d44..357079a4bcffe 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -218,6 +218,7 @@ public function initialize(array $query = array(), array $request = array(), arr $this->content = $content; $this->languages = null; $this->charsets = null; + $this->encodings = null; $this->acceptableContentTypes = null; $this->pathInfo = null; $this->requestUri = null; @@ -386,6 +387,7 @@ public function duplicate(array $query = null, array $request = null, array $att } $dup->languages = null; $dup->charsets = null; + $dup->encodings = null; $dup->acceptableContentTypes = null; $dup->pathInfo = null; $dup->requestUri = null; @@ -1444,6 +1446,21 @@ public function getCharsets() return $this->charsets = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Charset'))->all()); } + /** + * Gets a list of encodings acceptable by the client browser. + * + * @return array List of encodings in preferable order + * + * @api + */ + public function getEncodings() + { + if (null !== $this->encodings) { + return $this->encodings; + } + return $this->encodings = array_keys(AcceptHeader::fromString($this->headers->get('Accept-Encoding'))->all()); + } + /** * Gets a list of content types acceptable by the client browser * diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 5ba94f7ed750f..42f5500980fd8 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1122,6 +1122,22 @@ public function testGetCharsets() $this->assertEquals(array('ISO-8859-1', 'utf-8', '*'), $request->getCharsets()); } + public function testGetEncodings() + { + $request = new Request(); + $this->assertEquals(array(), $request->getEncodings()); + $request->headers->set('Accept-Encoding', 'gzip,deflate,sdch'); + $this->assertEquals(array(), $request->getEncodings()); // testing caching + + $request = new Request(); + $request->headers->set('Accept-Encoding', 'gzip,deflate,sdch'); + $this->assertEquals(array('gzip', 'deflate', 'sdch'), $request->getEncodings()); + + $request = new Request(); + $request->headers->set('Accept-Encoding', 'gzip;q=0.4,deflate;q=0.9,compress;q=0.7'); + $this->assertEquals(array('deflate', 'compress', 'gzip'), $request->getEncodings()); + } + public function testGetAcceptableContentTypes() { $request = new Request(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy