Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support file stream #4897

Closed
wants to merge 1 commit into from

2 participants

@ClemensSahs

hallo I think I found a forgotten code area ;)

near this line

if we have a file resource, the CURL adapter try to get the file size from the header "content-lenght".

we have on the $headers var a array like this

array(7) {
  ["Host"]=>
  string(14) "127.0.0.1:5984"
  ["Connection"]=>
  string(5) "close"
  ["Accept-Encoding"]=>
  string(13) "gzip, deflate"
  ["User-Agent"]=>
  string(16) "Zend\Http\Client"
  ["Content-Type"]=>
  string(16) "application/json"
  ["Content-Length"]=>
  string(2) "26"
  ["content-type"]=>
  string(16) "application/json"
}

but he try it detect form the value with preg_match()

foreach ($headers AS $k => $header) {
    if (preg_match('/Content-Length:\s*(\d+)/i', $header, $m)) {
        if (is_resource($body)) {
            $this->config['curloptions'][CURLOPT_INFILESIZE] = (int) $m[1];
        }
    unset($headers[$k]);
    }
}

If the old code has a reason so correct me

best regards

@ClemensSahs ClemensSahs fix wrong use from Headers array
we have here the array index "Content-Length" and a value typed integer
bd7ed1d
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#4897] Fix condition
- If the CURLOPT_INFILESIZE option *is* available, but no content-length
  header is sent, we can proceed. Only reset the CURLOPT_INFILESIZE if
  the content-length header is present.
6cde7cd
@weierophinney

Cherry-picked to master for release with 2.2.3.

@ClemensSahs ClemensSahs deleted the ClemensSahs:supportFileStream branch
@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
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#4897] Fix condition
- If the CURLOPT_INFILESIZE option *is* available, but no content-length
  header is sent, we can proceed. Only reset the CURLOPT_INFILESIZE if
  the content-length header is present.
9706f30
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-http
@weierophinney weierophinney Merge branch 'hotfix/4897' 339b92d
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-http
@weierophinney weierophinney Merge branch 'hotfix/4897' into develop 354bdfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 29, 2013
  1. @ClemensSahs

    fix wrong use from Headers array

    ClemensSahs authored
    we have here the array index "Content-Length" and a value typed integer
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 10 deletions.
  1. +4 −10 library/Zend/Http/Client/Adapter/Curl.php
View
14 library/Zend/Http/Client/Adapter/Curl.php
@@ -278,19 +278,13 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
if (isset($this->config['curloptions'][CURLOPT_INFILE])) {
// Now we will probably already have Content-Length set, so that we have to delete it
// from $headers at this point:
- foreach ($headers AS $k => $header) {
- if (preg_match('/Content-Length:\s*(\d+)/i', $header, $m)) {
- if (is_resource($body)) {
- $this->config['curloptions'][CURLOPT_INFILESIZE] = (int) $m[1];
- }
- unset($headers[$k]);
- }
- }
-
- if (!isset($this->config['curloptions'][CURLOPT_INFILESIZE])) {
+ if ( !isset($headers['Content-Length']) ) {
throw new AdapterException\RuntimeException("Cannot set a file-handle for cURL option CURLOPT_INFILE without also setting its size in CURLOPT_INFILESIZE.");
}
+ $this->config['curloptions'][CURLOPT_INFILESIZE] = (int) $headers['Content-Length'];
+ unset($headers['Content-Length']);
+
if (is_resource($body)) {
$body = '';
}
Something went wrong with that request. Please try again.