Development

Changeset 8497

You must first sign up to be able to contribute.

Changeset 8497

Show
Ignore:
Timestamp:
04/17/08 08:06:14 (1 year ago)
Author:
fabien
Message:

fixed content_type setting in view.yml is ignored (closes #3254)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/response/sfWebResponse.class.php

    r7969 r8497  
    107107    } 
    108108 
    109     $this->setContentType(isset($this->options['content_type']) ? $this->options['content_type'] : 'text/html'); 
     109    $this->options['content_type'] = $this->fixContentType(isset($this->options['content_type']) ? $this->options['content_type'] : 'text/html'); 
    110110  } 
    111111 
     
    263263  public function setContentType($value) 
    264264  { 
    265     // add charset if needed (only on text content) 
    266     if (false === stripos($value, 'charset') && (0 === stripos($value, 'text/') || strlen($value) - 3 === strripos($value, 'xml'))) 
    267     { 
    268       $value .= '; charset='.$this->options['charset']; 
    269     } 
    270  
    271     $this->headers['Content-Type'] = $value; 
     265    $this->headers['Content-Type'] = $this->fixContentType($value); 
    272266  } 
    273267 
     
    279273  public function getContentType() 
    280274  { 
    281     return $this->getHttpHeader('Content-Type'); 
    282   } 
    283  
    284   /** 
    285    * Send HTTP headers and cookies. 
     275    return $this->getHttpHeader('Content-Type', $this->options['content_type']); 
     276  } 
     277 
     278  /** 
     279   * Sends HTTP headers and cookies. 
    286280   * 
    287281   */ 
     
    303297 
    304298    // headers 
     299    if (!$this->getHttpHeader('Content-Type')) 
     300    { 
     301      $this->setContentType($this->options['content_type']); 
     302    } 
    305303    foreach ($this->headers as $name => $value) 
    306304    { 
     
    771769    } 
    772770  } 
     771 
     772  /** 
     773   * Fixes the content type by adding the charset for text content types. 
     774   * 
     775   * @param string The content type 
     776   * 
     777   * @param string The content type with the charset if needed 
     778   */ 
     779  protected function fixContentType($contentType) 
     780  { 
     781    // add charset if needed (only on text content) 
     782    if (false === stripos($contentType, 'charset') && (0 === stripos($contentType, 'text/') || strlen($contentType) - 3 === strripos($contentType, 'xml'))) 
     783    { 
     784      $contentType .= '; charset='.$this->options['charset']; 
     785    } 
     786 
     787    return $contentType; 
     788  } 
    773789} 
  • branches/1.1/test/functional/fixtures/project/apps/frontend/modules/view/actions/actions.class.php

    r2932 r8497  
    1515    $this->setTemplate('foo'); 
    1616  } 
     17 
     18  public function executePlain() 
     19  { 
     20  } 
     21 
     22  public function executeImage() 
     23  { 
     24  } 
    1725} 
  • branches/1.1/test/functional/fixtures/project/apps/frontend/modules/view/config/view.yml

    r2932 r8497  
    66  metas: 
    77    title: index title 
     8 
     9plainSuccess: 
     10  http_metas: 
     11    content-type: text/plain 
     12 
     13imageSuccess: 
     14  http_metas: 
     15    content-type: image/jpg 
     16  has_layout: false 
  • branches/1.1/test/functional/genericTest.php

    r8455 r8497  
    163163  get('/view')-> 
    164164  isStatusCode(200)-> 
     165  isResponseHeader('Content-Type', 'text/html; charset=utf-8')-> 
    165166  checkResponseElement('head title', 'foo title') 
     167; 
     168 
     169// view.yml with other than default content-type 
     170$b-> 
     171  get('/view/plain')-> 
     172  isStatusCode(200)-> 
     173  isResponseHeader('Content-Type', 'text/plain; charset=utf-8')-> 
     174  responseContains('<head>')-> 
     175  responseContains('plaintext') 
     176; 
     177 
     178// view.yml with other than default content-type and no layout 
     179$b-> 
     180  get('/view/image')-> 
     181  isStatusCode(200)-> 
     182  isResponseHeader('Content-Type', 'image/jpg')-> 
     183  responseContains('image') 
    166184; 
    167185 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.