Changeset 942

Show
Ignore:
Timestamp:
07/23/08 18:47:30 (2 months ago)
Author:
kaste
Message:

Request parses MimeType? more according to the http-specifications.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/restful-service/lib/AkRequest.php

    r895 r942  
    331331    private function parseMimeType($mime_type) 
    332332    { 
    333         @list($type,$parameter_string) = explode(';',$mime_type); 
     333        @list($type,$parameter_string) = explode(';',$mime_type,2); 
    334334        $mime_type_struct = array(); 
    335335        if ($parameter_string){ 
    336             parse_str($parameter_string,$mime_type_struct); 
     336            foreach (explode(';',$parameter_string) as $parameter){ 
     337                if (strstr($parameter,'=')){ 
     338                    list($key,$value) = explode('=',$parameter); 
     339                    $mime_type_struct[$key] = $value; 
     340                }else{ 
     341                    $mime_type_struct[] = $parameter; 
     342                } 
     343            } 
    337344        } 
    338345        $mime_type_struct['type'] = trim($type); 
  • branches/restful-service/test/unit2/AkRequest/AcceptHeader.php

    r892 r942  
    2727        $this->Request->env['HTTP_ACCEPT'] = 'text/html'; 
    2828        $this->assertEquals(array('type'=>'text/html','q'=>'1.0'),array_pop($this->Request->getAcceptHeader())); 
     29    } 
     30     
     31    function testMimetypeParserRecoginzesAdditionalParameters() 
     32    { 
     33        $this->Request->env['HTTP_ACCEPT'] = 'text/html;q=0.9;key=value;throw_away'; 
     34        $this->assertEquals(array('type'=>'text/html','q'=>'0.9','key'=>'value','throw_away'),array_pop($this->Request->getAcceptHeader())); 
     35    } 
     36     
     37    function testMimetypeParserHandleFalseParametersNice() 
     38    { 
     39        $this->Request->env['HTTP_ACCEPT'] = 'text/xml;throw_away'; 
     40        $this->assertEquals('xml',$this->Request->getFormat()); 
    2941    } 
    3042