Skip to content

Commit

Permalink
To get length of binary, add strlen(, 'ASCII') method , & replacing Z…
Browse files Browse the repository at this point in the history
…F1's mb_internal_encoding hack
  • Loading branch information
sasezaki committed Oct 31, 2011
1 parent 2815974 commit 07bd8ef
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions library/Zend/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ protected function prepareHeaders($body, $uri)
$fstat = fstat($body);
$headers['Content-Length'] = $fstat['size'];
} else {
$headers['Content-Length'] = strlen($body);
$headers['Content-Length'] = static::strlen($body);
}
}

Expand All @@ -1106,19 +1106,8 @@ protected function prepareBody()
return '';
}

// If mbstring overloads substr and strlen functions, we have to
// override it's internal encoding
if (function_exists('mb_internal_encoding') &&
((int) ini_get('mbstring.func_overload')) & 2) {
$mbIntEnc = mb_internal_encoding();
mb_internal_encoding('ASCII');
}

$rawBody = $this->getRequest()->getContent();
if (!empty($rawBody)) {
if (isset($mbIntEnc)) {
mb_internal_encoding($mbIntEnc);
}
return $rawBody;
}

Expand Down Expand Up @@ -1158,11 +1147,6 @@ protected function prepareBody()
} else {
throw new Exception\RuntimeException("Cannot handle content type '{$this->encType}' automatically");
}

}

if (isset($mbIntEnc)) {
mb_internal_encoding($mbIntEnc);
}

return $body;
Expand Down Expand Up @@ -1238,6 +1222,7 @@ public function encodeFormData($boundary, $name, $value, $filename = null, $head

return $ret;
}

/**
* Convert an array of parameters into a flat array of (key, value) pairs
*
Expand Down Expand Up @@ -1283,4 +1268,20 @@ protected function flattenParametersArray($parray, $prefix = null)

return $parameters;
}

/**
* Returns length of binary string in bytes
*
* @param string $str
* @return int the string length
*/
static public function strlen($str)
{
if (function_exists('mb_internal_encoding') &&
(((int)ini_get('mbstring.func_overload')) & 2)) {
return mb_strlen($str, 'ASCII');
} else {
return strlen($str);
}
}
}

0 comments on commit 07bd8ef

Please sign in to comment.