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();
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: