Skip to content

Instantly share code, notes, and snippets.

@isaiahdw
Created December 29, 2010 01:01
Show Gist options
  • Save isaiahdw/757990 to your computer and use it in GitHub Desktop.
Save isaiahdw/757990 to your computer and use it in GitHub Desktop.
classes/kohana/response.php | 34 +++++++++++++++++++++++++---------
1 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/classes/kohana/response.php b/classes/kohana/response.php
index 6ec1a28..ad856b9 100644
--- a/classes/kohana/response.php
+++ b/classes/kohana/response.php
@@ -177,6 +177,11 @@ class Kohana_Response implements Http_Response, Serializable {
protected $_protocol;
/**
+ * @var string The length of the response body
+ */
+ protected $_content_length = NULL;
+
+ /**
* Sets up the response object
*
* @param array $config Setup the response object
@@ -388,6 +393,23 @@ class Kohana_Response implements Http_Response, Serializable {
}
/**
+ * Set content length
+ *
+ * @return void
+ */
+ public function set_content_length($length = NULL)
+ {
+ if ($length === NULL)
+ {
+ $this->_content_length = $this->content_length();
+ }
+ else
+ {
+ $this->_content_length = $length;
+ }
+ }
+
+ /**
* Sends the response status and all set headers.
*
* @return Response
@@ -413,16 +435,10 @@ class Kohana_Response implements Http_Response, Serializable {
$this->_header['x-powered-by'] = 'Kohana Framework '.Kohana::VERSION.' ('.Kohana::CODENAME.')';
}
- // If in production, include the content length in the response
- if (Kohana::$environment === Kohana::PRODUCTION)
+ // Include the content length in the response if we have one
+ if ($this->_content_length)
{
- $content_length = $this->content_length();
-
- // Set the content length for the body if required
- if ($content_length > 0)
- {
- $this->_header['content-length'] = (string) $content_length;
- }
+ $this->_header['content-length'] = $this->_content_length;
}
// HTTP status line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment