Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add method to Zend\Http\Response\Stream #3498

Merged
merged 2 commits into from

3 participants

@prolic

the content length is now exposed with getters and setters

@prolic prolic add method to Zend\Http\Response\Stream
the content length is now exposed with getters and setters
7da4fc6
@samsonasik

i think, in readStream function, change atrribute $this->contentlength to getContentLength()

@prolic prolic add method to Zend\Http\Response\Stream
the content length is now exposed with getters and setters
fixed phpdoc
change atrribute $this->contentlength to getContentLength()
f932275
@weierophinney weierophinney commented on the diff
library/Zend/Http/Response/Stream.php
@@ -182,12 +202,12 @@ public static function fromStream($responseString, $stream)
$headers = $response->getHeaders();
foreach ($headers as $header) {
if ($header instanceof \Zend\Http\Header\ContentLength) {
- $response->contentLength = (int) $header->getFieldValue();
- if (strlen($response->content) > $response->contentLength) {
+ $response->setContentLength((int) $header->getFieldValue());
+ if (strlen($response->content) > $response->getContentLength()) {
@weierophinney Owner

retrieve the content length into a local variable, as it's fetched twice on a valid condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#3498] Minor logic changes
- Cache return of method call -- prevents multiple fetches
- use "null !==" instead of "!is_null" (internal consistency)
8515df8
@weierophinney weierophinney merged commit f932275 into zendframework:develop
@prolic prolic deleted the prolic:stream branch
@Maks3w Maks3w referenced this pull request from a commit in Maks3w/zf2
@weierophinney weierophinney Merge branch 'hotfix/3498' into develop
Close #3498
1432ed3
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney [#3498] Minor logic changes
- Cache return of method call -- prevents multiple fetches
- use "null !==" instead of "!is_null" (internal consistency)
22fd243
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3498' into develop
Close #3498
7dbd70d
@weierophinney weierophinney referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@weierophinney weierophinney referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-http
@weierophinney weierophinney [zendframework/zf2#3498] Minor logic changes
- Cache return of method call -- prevents multiple fetches
- use "null !==" instead of "!is_null" (internal consistency)
23877c5
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-http
@weierophinney weierophinney Merge branch 'hotfix/3498' into develop 774723b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 20, 2013
  1. @prolic

    add method to Zend\Http\Response\Stream

    prolic authored
    the content length is now exposed with getters and setters
  2. @prolic

    add method to Zend\Http\Response\Stream

    prolic authored
    the content length is now exposed with getters and setters
    fixed phpdoc
    change atrribute $this->contentlength to getContentLength()
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 6 deletions.
  1. +27 −6 library/Zend/Http/Response/Stream.php
View
33 library/Zend/Http/Response/Stream.php
@@ -60,6 +60,26 @@ class Stream extends Response
protected $cleanup;
/**
+ * Set content length
+ *
+ * @param int $contentLength
+ */
+ public function setContentLength($contentLength = null)
+ {
+ $this->contentLength = $contentLength;
+ }
+
+ /**
+ * Get content length
+ *
+ * @return int|null
+ */
+ public function getContentLength()
+ {
+ return $this->contentLength;
+ }
+
+ /**
* Get the response as stream
*
* @return resource
@@ -182,12 +202,12 @@ public static function fromStream($responseString, $stream)
$headers = $response->getHeaders();
foreach ($headers as $header) {
if ($header instanceof \Zend\Http\Header\ContentLength) {
- $response->contentLength = (int) $header->getFieldValue();
- if (strlen($response->content) > $response->contentLength) {
+ $response->setContentLength((int) $header->getFieldValue());
+ if (strlen($response->content) > $response->getContentLength()) {
@weierophinney Owner

retrieve the content length into a local variable, as it's fetched twice on a valid condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
throw new Exception\OutOfRangeException(sprintf(
'Too much content was extracted from the stream (%d instead of %d bytes)',
strlen($response->content),
- $response->contentLength
+ $response->getContentLength()
));
}
break;
@@ -242,8 +262,9 @@ public function getRawBody()
*/
protected function readStream()
{
- if (!is_null($this->contentLength)) {
- $bytes = $this->contentLength - $this->contentStreamed;
+ $contentLength = $this->getContentLength();
+ if (!is_null($contentLength)) {
+ $bytes = $contentLength - $this->contentStreamed;
} else {
$bytes = -1; //Read the whole buffer
}
@@ -255,7 +276,7 @@ protected function readStream()
$this->content .= stream_get_contents($this->stream, $bytes);
$this->contentStreamed += strlen($this->content);
- if ($this->contentLength == $this->contentStreamed) {
+ if ($this->getContentLength() == $this->contentStreamed) {
$this->stream = null;
}
}
Something went wrong with that request. Please try again.