Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

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

Closed
wants to merge 1 commit into from
Closed

Conversation

alexhenrie
Copy link
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.

@samsonasik
Copy link
Contributor

travis build failure, see https://travis-ci.org/zendframework/zf2/jobs/21356359#L583

@Maks3w
Copy link
Member

Maks3w commented Mar 23, 2014

Please add a unit test

@alexhenrie
Copy link
Contributor Author

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 this to the 2.3.1 milestone Apr 2, 2014
@Ocramius Ocramius self-assigned this Apr 2, 2014
Ocramius added a commit that referenced this pull request Apr 2, 2014
@Ocramius Ocramius closed this in 23e072b Apr 2, 2014
Ocramius added a commit that referenced this pull request Apr 2, 2014
@alexhenrie
Copy link
Contributor Author

Thank you!

gianarb pushed a commit to zendframework/zend-http that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-http that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-http that referenced this pull request May 15, 2015
gianarb pushed a commit to zendframework/zend-http that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants