Allow empty response strings in \Zend\Http\Response::fromStream #6027

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

@alexhenrie
Contributor

If the explode function is only passed 2 parameters, it will always return an array of size 1 or greater, which means that $headerComplete will be set to true whether or not there was actually any data in the response string. This causes \Zend\Http\Response::fromStream to fail without reason.

For example, if you wanted to proxy the English Wikipedia's main page, you might say:

public function indexAction() {
    $socket = fsockopen('en.wikipedia.org', 80);
    fwrite($socket, "GET /wiki/Main_Page\nHost: en.wikipedia.org\n\n");
    $ret = \Zend\Http\Response\Stream::fromStream('', $socket);
    return $ret;
}

In the current version of Zend Framework, this example results in the following error:

Zend\Http\Exception\InvalidArgumentException
vendor/zendframework/zendframework/library/Zend/Http/Response.php:184
A valid response status line was not found in the provided string

There is no good reason to produce an error here. With my attached code, the request is honored and processed normally.

@Maks3w
Member
Maks3w commented Mar 23, 2014

Please add a unit test

@alexhenrie
Contributor

Okay, I've corrected my code and added a new test for it. The test failure reported on PHP 5.5 does not appear to be related to this change.

@Ocramius Ocramius added Http bug labels Apr 2, 2014
@Ocramius Ocramius added this to the 2.3.1 milestone Apr 2, 2014
@Ocramius Ocramius self-assigned this Apr 2, 2014
@Ocramius Ocramius added a commit that referenced this pull request Apr 2, 2014
@Ocramius Ocramius Minor conditional simplification for #6027 1718beb
@Ocramius Ocramius closed this in 23e072b Apr 2, 2014
@Ocramius Ocramius added a commit that referenced this pull request Apr 2, 2014
@Ocramius Ocramius Merge branch 'hotfix/#6027-http-response-from-stream-status-code' int…
…o develop

Close #6027
Forward Port #6027
d394994
@alexhenrie
Contributor

Thank you!

@gianarb gianarb pushed a commit to zendframework/zend-http that referenced this pull request May 15, 2015
@Ocramius Ocramius Minor conditional simplification for zendframework/zendframework#6027 77c7db1
@gianarb gianarb pushed a commit to zendframework/zend-http that referenced this pull request May 15, 2015
@Ocramius Ocramius Merge branch 'hotfix/zendframework/zf2#6027-http-response-from-stream…
…-status-code'

Close zendframework/zendframework#6027
562ad2a
@gianarb gianarb pushed a commit to zendframework/zend-http that referenced this pull request May 15, 2015
@Ocramius Ocramius Merge branch 'hotfix/zendframework/zf2#6027-http-response-from-stream…
…-status-code' into develop

Close zendframework/zendframework#6027
Forward Port zendframework/zendframework#6027
523bb9b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment