Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setContentlength() method to Phalcon\Http\Response #11986

Merged
merged 1 commit into from
Jul 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
- Amended `Phalcon\Mvc\RouterInterface` and `Phalcon\Mvc\Router`. Added missed `addPurge`, `addTrace` and `addConnect` methods
- Fixed incorrect query when using NULL fields with `Phalcon\Validation\Validator\Uniqueness`
- Fixed `Phalcon\Forms\Form::getValue`. Now Elements can have names that match with the internal Form getters [#10398](https://github.com/phalcon/cphalcon/issues/10398)
- Add `setContentLength()` method to `Phalcon\Http\Response`

# [2.0.13](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.13) (2016-05-19)
- Restored `Phalcon\Text::camelize` behavior [#11767](https://github.com/phalcon/cphalcon/issues/11767)
Expand Down
39 changes: 15 additions & 24 deletions phalcon/http/response.zep
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
| Zamrony P. Juhara <zamronypj@yahoo.com> |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new author just for doing a patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I thought every contributors have right to put their name. I thought we value every contribution even smallest one? I do not get financial reward to do this work so putting my name is my reward. Your statement discourages people to contribute.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically andres and eduar are added as authors always beacause they are authors of frameworks and you can you as author if you are creating new file, but othey than that authors should stay the same.

+------------------------------------------------------------------------+
*/

Expand Down Expand Up @@ -59,10 +60,6 @@ class Response implements ResponseInterface, InjectionAwareInterface

/**
* Phalcon\Http\Response constructor
*
* @param string content
* @param int code
* @param string status
*/
public function __construct(content = null, code = null, status = null)
{
Expand Down Expand Up @@ -279,10 +276,6 @@ class Response implements ResponseInterface, InjectionAwareInterface
*<code>
* $response->setHeader("Content-Type", "text/plain");
*</code>
*
* @param string name
* @param string value
* @return \Phalcon\Http\Response
*/
public function setHeader(string name, value) -> <Response>
{
Expand Down Expand Up @@ -406,10 +399,6 @@ class Response implements ResponseInterface, InjectionAwareInterface
* $response->setContentType('application/pdf');
* $response->setContentType('text/plain', 'UTF-8');
*</code>
*
* @param string contentType
* @param string charset
* @return \Phalcon\Http\Response
*/
public function setContentType(string contentType, charset = null) -> <Response>
{
Expand All @@ -422,6 +411,20 @@ class Response implements ResponseInterface, InjectionAwareInterface
return this;
}

/**
* Sets the response content-length
*
*<code>
* $response->setContentLength(2048);
*</code>
*/
public function setContentLength(int contentLength) -> <Response>
{
this->setHeader("Content-Length", contentLength);

return this;
}

/**
* Set a custom ETag
*
Expand Down Expand Up @@ -452,11 +455,6 @@ class Response implements ResponseInterface, InjectionAwareInterface
* "controller" => "index"
* ));
*</code>
*
* @param string|array location
* @param boolean externalRedirect
* @param int statusCode
* @return \Phalcon\Http\Response
*/
public function redirect(location = null, boolean externalRedirect = false, int statusCode = 302) -> <Response>
{
Expand Down Expand Up @@ -542,9 +540,6 @@ class Response implements ResponseInterface, InjectionAwareInterface

/**
* Appends a string to the HTTP response body
*
* @param string content
* @return \Phalcon\Http\Response
*/
public function appendContent(content) -> <Response>
{
Expand Down Expand Up @@ -626,10 +621,6 @@ class Response implements ResponseInterface, InjectionAwareInterface

/**
* Sets an attached file to be sent at the end of the request
*
* @param string filePath
* @param string attachmentName
* @return \Phalcon\Http\Response
*/
public function setFileToSend(string filePath, attachmentName = null, attachment = true) -> <Response>
{
Expand Down
25 changes: 7 additions & 18 deletions phalcon/http/responseinterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
| Zamrony P. Juhara <zamronypj@yahoo.com> |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same

+------------------------------------------------------------------------+
*/

Expand Down Expand Up @@ -41,10 +42,6 @@ interface ResponseInterface

/**
* Overwrites a header in the response
*
* @param string name
* @param string value
* @return \Phalcon\Http\ResponseInterface
*/
public function setHeader(string name, value) -> <ResponseInterface>;

Expand All @@ -62,6 +59,7 @@ interface ResponseInterface
* Sets output expire time header
*/
public function setExpires(<\DateTime> datetime) -> <ResponseInterface>;

/**
* Sends a Not-Modified response
*/
Expand All @@ -76,13 +74,13 @@ interface ResponseInterface
*/
public function setContentType(string contentType, charset = null) -> <ResponseInterface>;

/**
* Sets the response content-length
*/
public function setContentLength(int contentLength) -> <ResponseInterface>;

/**
* Redirect by HTTP to another action or URL
*
* @param string location
* @param boolean externalRedirect
* @param int statusCode
* @return \Phalcon\Http\ResponseInterface
*/
public function redirect(location = null, boolean externalRedirect = false, int statusCode = 302) -> <ResponseInterface>;

Expand All @@ -97,17 +95,11 @@ interface ResponseInterface
*<code>
* response->setJsonContent(array("status" => "OK"));
*</code>
*
* @param string content
* @return \Phalcon\Http\ResponseInterface
*/
public function setJsonContent(content) -> <ResponseInterface>;

/**
* Appends a string to the HTTP response body
*
* @param string content
* @return \Phalcon\Http\ResponseInterface
*/
public function appendContent(content) -> <ResponseInterface>;

Expand All @@ -133,9 +125,6 @@ interface ResponseInterface

/**
* Sets an attached file to be sent at the end of the request
*
* @param string filePath
* @param string attachmentName
*/
public function setFileToSend(string filePath, attachmentName = null) -> <ResponseInterface>;

Expand Down
26 changes: 26 additions & 0 deletions tests/unit/Http/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @link http://www.phalconphp.com
* @author Andres Gutierrez <andres@phalconphp.com>
* @author Nikolaos Dimopoulos <nikos@phalconphp.com>
* @author Zamrony P. Juhara <zamronypj@yahoo.com>
* @package Phalcon\Test\Unit\Http
*
* The contents of this file are subject to the New BSD License that is
Expand Down Expand Up @@ -261,6 +262,31 @@ function () {
);
}

/**
* Tests the setContentLength
*
* @author Zamrony P. Juhara <zamronypj@yahoo.com>
* @since 2016-07-18
*/
public function testHttpResponseSetContentLength()
{
$this->specify(
"setContentLength is not setting the header properly",
function () {
$response = $this->getResponseObject();
$response->resetHeaders();
$response->setContentLength(100);

$expected = Headers::__set_state(
[
'_headers' => ['Content-Length' => 100]
]
);
expect($response->getHeaders())->equals($expected);
}
);
}

/**
* Tests the setContentType with charset
*
Expand Down