Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1123 from chillu/pulls/revert-content-length

API Remove Content-Length setting from HTTPResponse (fixes #8010)
  • Loading branch information...
commit d77e06d58516ee32ead9c6ce193846fa3192fa52 2 parents 1bb1090 + c69381c
@chillu chillu authored
View
11 control/Director.php
@@ -148,17 +148,6 @@ public static function direct($url, DataModel $model) {
number_format(memory_get_peak_usage(),0)
));
} else {
- // Set content length (according to RFC2616)
- if(
- !headers_sent()
- && $response->getBody()
- && $req->httpMethod() != 'HEAD'
- && $response->getStatusCode() >= 200
- && !in_array($response->getStatusCode(), array(204, 304))
- ) {
- $response->fixContentLength();
- }
-
$response->output();
}
} else {
View
11 control/HTTPResponse.php
@@ -150,6 +150,9 @@ public function isError() {
public function setBody($body) {
$this->body = $body;
+
+ // Set content-length in bytes. Use mbstring to avoid problems with mb_internal_encoding() and mbstring.func_overload
+ $this->headers['Content-Length'] = mb_strlen($this->body,'8bit');
}
public function getBody() {
@@ -252,14 +255,6 @@ public function output() {
public function isFinished() {
return in_array($this->statusCode, array(301, 302, 401, 403));
}
-
- /**
- * Set content-length in bytes. Should be called right before {@link output()}.
- */
- public function fixContentLength() {
- // Use mbstring to avoid problems with mb_internal_encoding() and mbstring.func_overload
- $this->headers['Content-Length'] = mb_strlen($this->body,'8bit');
- }
}
View
2  tests/control/HTTPResponseTest.php
@@ -15,7 +15,6 @@ public function testStatusDescriptionStripsNewlines() {
public function testContentLengthHeader() {
$r = new SS_HTTPResponse('123ü');
- $r->fixContentLength();
$this->assertNotNull($r->getHeader('Content-Length'), 'Content-length header is added');
$this->assertEquals(
5,
@@ -24,7 +23,6 @@ public function testContentLengthHeader() {
);
$r->setBody('1234ü');
- $r->fixContentLength();
$this->assertEquals(
6,
$r->getHeader('Content-Length'),
Please sign in to comment.
Something went wrong with that request. Please try again.