silverstripe-framework/tests/control/HTTPResponseTest.php
Ingo Schommer c69381c33e API Remove Content-Length setting from HTTPResponse (fixes #8010)
This reverts commit 356a367eb5.
We can't use headers_sent() to determine an accurate
content length, since PHP defaults to buffering a couple of bytes
even without ob_start() (see "output_buffering" setting).
This makes the patch harmful, since it breaks any responses relying
on more structure data, like removing closing brackets from JSON.
Which in turn breaks the CMS in horrible ways (see #8010).
See #7574 for context.
2013-01-23 15:05:33 +01:00

34 lines
827 B
PHP

<?php
/**
* @package framework
* @subpackage tests
*/
class HTTPResponseTest extends SapphireTest {
public function testStatusDescriptionStripsNewlines() {
$r = new SS_HTTPResponse('my body', 200, "my description \nwith newlines \rand carriage returns");
$this->assertEquals(
"my description with newlines and carriage returns",
$r->getStatusDescription()
);
}
public function testContentLengthHeader() {
$r = new SS_HTTPResponse('123ü');
$this->assertNotNull($r->getHeader('Content-Length'), 'Content-length header is added');
$this->assertEquals(
5,
$r->getHeader('Content-Length'),
'Header matches actual content length in bytes'
);
$r->setBody('1234ü');
$this->assertEquals(
6,
$r->getHeader('Content-Length'),
'Header is updated when body is changed'
);
}
}