nategood / httpful

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problems with stripping CURLs proxy response output

KingPrawnBalls opened this issue · comments

The proxy response stripping code in Request->send() function has two issues preventing it from working with our proxy:

  1. it only checks for HTTP/1.0 not 1.x before the "Connection established" string
  2. it doesn't strip further HTTP headers returned by the proxy after the status line (see http://curl.haxx.se/mail/lib-2005-10/0023.html for examples)

I suggest this code change, which has fixed both issues for us:

/** Remove the "HTTP/1.x 200 Connection established" string and any other headers added by proxy
 *  RegEx notes:
 *     /s   - this option after the match string changes . char to also match newlines
 *     .*?  - the ? makes the * lazy rather than it's normal greedy behaviour, so it doesn't consume the \r\n\r\n following it
 */
if ($this->hasProxy() && preg_match("/HTTP\/1\.[01] 200 Connection established.*?\r\n\r\n/s", $result)) {
  $result = preg_replace("/HTTP\/1\.[01] 200 Connection established.*?\r\n\r\n/s", '', $result);
}

Thanks Paul. I'll review shortly.
On Feb 28, 2014 8:03 AM, "Paul Harding" notifications@github.com wrote:

The proxy response stripping code in Request->send() function has two
issues preventing it from working with our proxy:

  1. it only checks for HTTP/1.0 not 1.x before the "Connection established"
    string
  2. it doesn't strip further HTTP headers returned by the proxy after the
    status line (see http://curl.haxx.se/mail/lib-2005-10/0023.html for
    examples)

I suggest this code change, which has fixed both issues for us:

/** Remove the "HTTP/1.x 200 Connection established" string and any other headers added by proxy

  • RegEx notes:
  • /s   - this option after the match string changes . char to also match newlines
    
  • ._?  - the ? makes the \* lazy rather than it's normal greedy behaviour, so it doesn't consume the \r\n\r\n following it
    
    /
    if ($this->hasProxy() && preg_match("/HTTP/1.[01] 200 Connection established._?\r\n\r\n/s", $result)) {
    $result = preg_replace("/HTTP/1.[01] 200 Connection established.
    ?\r\n\r\n/s", '', $result);
    }

Reply to this email directly or view it on GitHubhttps://github.com//issues/122
.

Hi Nate, did you get any time to look over this?

Great! Thanks