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

fixed removing handled header parts from response header #6691

Conversation

kasitmp
Copy link

@kasitmp kasitmp commented Sep 23, 2014

This fix should solve two potential issues:

  1. $this->response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $this->response); is able to remove content, also from a response body. To solve this I separate the header from the body first before manipulating the it.
  2. There are pages in the wild which return headers with more than one space between Transfer-Encoding: and chunked. This fix should solve these issues via regex

I coded this to fix my issue #6689

@Martin-P
Copy link
Contributor

Perhaps you can create testcases for the issues you describe to prevent this bug from returning due to future changes?

@kasitmp
Copy link
Author

kasitmp commented Sep 27, 2014

I tried to do it the way you did your tests, however I don't think it is a good way to do actually requests to a webserver. In my case I tried it by creating a php response with header("Transfer-Encoding", " chunked"), but php trims the whitespace before chunked and removes the "test problem". I also saw that there were other "dynamic-tests" (that's how you call remote tests, I guess) failed after setting things up.
Wouldn't it be a good idea to build something that mocks responses from a text file rather than respond with interpreted php files? There is also the problem that it matters how your server is configured. Apache also enriches the header with information that changes the test behavior.

An idea would be to wrap curl in a class to mock the reponses. Then one could create tests that work even offline. But that would be a bigger change in code, so I would like to talk to someone before. I tried to contact some of you in your channel on irc, but nobody answers and I'm a bit busy.

@Ocramius
Copy link
Member

We may startup a small web server in travis in order to let all the http tests run also there...

@weierophinney
Copy link
Member

@kasitmp As @Ocramius noted, we can modify our Travis configuration to startup a web server using the built-in PHP webserver with versions 5.4+, and then test against that (we actually have tests already that only test against a web server that runs against a document root in the test hierarchy, and we use these for integration spot-checking). Alternately, you can create mock responses to test against (we also do this in a number of places). Considering this is cURL specific, you likely need to go with the first option.

We do need a test, however, to validate that this works. If you think you can work with us to make that happen in the next two weeks, I'll mark this for 2.4.

@kasitmp
Copy link
Author

kasitmp commented Feb 20, 2015

I'm really busy at the moment, but I will try. This is a while back so I will need some time to get back into my code, I guess :)
Count me in, I will try doing it during the next week.

@weierophinney weierophinney added this to the 2.4.0 milestone Feb 25, 2015
// separating header from body because it is dangerous to accidentially replace strings in the body
$responseHeaderSize = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE);
$responseHeaders = substr($this->response, 0, $responseHeaderSize);

// cURL automatically decodes chunked-messages, this means we have to disallow the Zend\Http\Response to do it again
Copy link
Author

Choose a reason for hiding this comment

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

I separated header from body, to be sure that i don't manipulate the body. Possible test:
Textfile with Transfer-Encoding: chunked\r\n inside AND the webserver must not make use of chunking.
In the old version the assert that the file is the same would probably fail.

@kasitmp
Copy link
Author

kasitmp commented Mar 4, 2015

I'm sorry, but I can't find time to do the tests at the moment. But I describe what I would test, if I would know how to do it with your infrastructure. Just look at the annotations https://github.com/zendframework/zf2/pull/6691/files

weierophinney added a commit that referenced this pull request Mar 18, 2015
…pter

fixed removing handled header parts from response header
weierophinney added a commit that referenced this pull request Mar 18, 2015
@weierophinney
Copy link
Member

Merged to develop for release with 2.4.

weierophinney added a commit to zendframework/zend-http that referenced this pull request May 15, 2015
…header-handling-in-curl-adapter

fixed removing handled header parts from response header
weierophinney added 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