Changeset 8497
- Timestamp:
- 04/17/08 08:06:14 (1 year ago)
- Files:
-
- branches/1.1/lib/response/sfWebResponse.class.php (modified) (5 diffs)
- branches/1.1/test/functional/fixtures/project/apps/frontend/modules/view/actions/actions.class.php (modified) (1 diff)
- branches/1.1/test/functional/fixtures/project/apps/frontend/modules/view/config/view.yml (modified) (1 diff)
- branches/1.1/test/functional/fixtures/project/apps/frontend/modules/view/templates/imageSuccess.php (added)
- branches/1.1/test/functional/fixtures/project/apps/frontend/modules/view/templates/plainSuccess.php (added)
- branches/1.1/test/functional/genericTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/response/sfWebResponse.class.php
r7969 r8497 107 107 } 108 108 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'); 110 110 } 111 111 … … 263 263 public function setContentType($value) 264 264 { 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); 272 266 } 273 267 … … 279 273 public function getContentType() 280 274 { 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. 286 280 * 287 281 */ … … 303 297 304 298 // headers 299 if (!$this->getHttpHeader('Content-Type')) 300 { 301 $this->setContentType($this->options['content_type']); 302 } 305 303 foreach ($this->headers as $name => $value) 306 304 { … … 771 769 } 772 770 } 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 } 773 789 } branches/1.1/test/functional/fixtures/project/apps/frontend/modules/view/actions/actions.class.php
r2932 r8497 15 15 $this->setTemplate('foo'); 16 16 } 17 18 public function executePlain() 19 { 20 } 21 22 public function executeImage() 23 { 24 } 17 25 } branches/1.1/test/functional/fixtures/project/apps/frontend/modules/view/config/view.yml
r2932 r8497 6 6 metas: 7 7 title: index title 8 9 plainSuccess: 10 http_metas: 11 content-type: text/plain 12 13 imageSuccess: 14 http_metas: 15 content-type: image/jpg 16 has_layout: false branches/1.1/test/functional/genericTest.php
r8455 r8497 163 163 get('/view')-> 164 164 isStatusCode(200)-> 165 isResponseHeader('Content-Type', 'text/html; charset=utf-8')-> 165 166 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') 166 184 ; 167 185

