예제 #1
0
 /**
  * Returns the quality of the `$encoding` type passed to it. Encoding
  * is usually compression such as `gzip`, but could be some other
  * message encoding algorithm. This method allows explicit checks to be
  * done ignoring wildcards.
  *
  *      // Accept-Encoding: compress, gzip, *; q=.5
  *      $encoding = $header->accepts_encoding_at_quality('gzip');
  *      // $encoding = (float) 1.0s
  *
  * @param   string  $encoding   encoding type to interrogate
  * @param   boolean $explicit   explicit check, ignoring wildcards and `identity`
  * @return  float
  * @since   3.2.0
  */
 public function accepts_encoding_at_quality($encoding, $explicit = FALSE)
 {
     if ($this->_accept_encoding === NULL) {
         if ($this->offsetExists('Accept-Encoding')) {
             $encoding_header = $this->offsetGet('Accept-Encoding');
         } else {
             $encoding_header = NULL;
         }
         $this->_accept_encoding = HTTP_Header::parse_encoding_header($encoding_header);
     }
     // Normalize the encoding
     $encoding = strtolower($encoding);
     if (isset($this->_accept_encoding[$encoding])) {
         return $this->_accept_encoding[$encoding];
     }
     if ($explicit === FALSE) {
         if (isset($this->_accept_encoding['*'])) {
             return $this->_accept_encoding['*'];
         } elseif ($encoding === 'identity') {
             return (double) HTTP_Header::DEFAULT_QUALITY;
         }
     }
     return (double) 0;
 }
예제 #2
0
 /**
  * Tests the `parse_encoding_header` method parses the Accept-Encoding header
  * correctly
  * 
  * @dataProvider provider_parse_encoding_header
  *
  * @param   string  $accept    accept 
  * @param   array   $expected  expected 
  * @return  void
  */
 public function test_parse_encoding_header($accept, array $expected)
 {
     $this->assertSame($expected, HTTP_Header::parse_encoding_header($accept));
 }