Skip to content

Commit

Permalink
Rename response_byte_limit to max_bytes
Browse files Browse the repository at this point in the history
Simplify, simplify, simplify.
  • Loading branch information
rmccue committed Oct 2, 2015
1 parent b9d3337 commit 73e85cf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions library/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public static function patch($url, $headers, $data = array(), $options = array()
* (Requests_Auth|array|boolean, default: false)
* - `proxy`: Proxy details to use for proxy by-passing and authentication
* (Requests_Proxy|array|boolean, default: false)
* - `response_byte_limit`: limit response body to first XXX bytes if set.
* - `max_bytes`: Limit for the response body size.
* (integer|boolean, default: false)
* - `idn`: Enable IDN parsing
* (boolean, default: true)
Expand Down Expand Up @@ -468,7 +468,7 @@ protected static function get_default_options($multirequest = false) {
'auth' => false,
'proxy' => false,
'cookies' => false,
'response_byte_limit' => false,
'max_bytes' => false,
'idn' => true,
'hooks' => null,
'transport' => null,
Expand Down
8 changes: 4 additions & 4 deletions library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public function request($url, $headers = array(), $data = array(), $options = ar
$this->response_data = '';
$this->response_bytes = 0;
$this->response_byte_limit = false;
if ($options['response_byte_limit'] !== false) {
$this->response_byte_limit = $options['response_byte_limit'];
if ($options['max_bytes'] !== false) {
$this->response_byte_limit = $options['max_bytes'];
}

if (isset($options['verify'])) {
Expand Down Expand Up @@ -249,8 +249,8 @@ public function &get_subrequest_handle($url, $headers, $data, $options) {
$this->response_data = '';
$this->response_bytes = 0;
$this->response_byte_limit = false;
if ($options['response_byte_limit'] !== false) {
$this->response_byte_limit = $options['response_byte_limit'];
if ($options['max_bytes'] !== false) {
$this->response_byte_limit = $options['max_bytes'];
}

return $this->fp;
Expand Down
10 changes: 5 additions & 5 deletions library/Requests/Transport/fsockopen.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function request($url, $headers = array(), $data = array(), $options = ar
$remote_socket = 'tcp://' . $host;
}

$this->response_byte_limit = $options['response_byte_limit'];
$this->max_bytes = $options['max_bytes'];

$proxy = isset( $options['proxy'] );
$proxy_auth = $proxy && isset( $options['proxy_username'] ) && isset( $options['proxy_password'] );
Expand Down Expand Up @@ -241,14 +241,14 @@ public function request($url, $headers = array(), $data = array(), $options = ar
// Are we in body mode now?
if ($doingbody) {
$data_length = strlen($block);
if ($this->response_byte_limit) {
if ($this->max_bytes) {
// Have we already hit a limit?
if ($size === $this->response_byte_limit) {
if ($size === $this->max_bytes) {
continue;
}
if (($size + $data_length) > $this->response_byte_limit) {
if (($size + $data_length) > $this->max_bytes) {
// Limit the length
$limited_length = ($this->response_byte_limit - $size);
$limited_length = ($this->max_bytes - $size);
$block = substr($block, 0, $limited_length);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Transport/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function getOptions($other = array()) {
public function testResponseByteLimit() {
$limit = 104;
$options = array(
'response_byte_limit' => $limit,
'max_bytes' => $limit,
);
$response = Requests::get(httpbin('/bytes/325'), array(), $this->getOptions($options));
$this->assertEquals($limit, strlen($response->body));
Expand All @@ -37,7 +37,7 @@ public function testResponseByteLimit() {
public function testResponseByteLimitWithFile() {
$limit = 300;
$options = array(
'response_byte_limit' => $limit,
'max_bytes' => $limit,
'filename' => tempnam(sys_get_temp_dir(), 'RLT') // RequestsLibraryTest
);
$response = Requests::get(httpbin('/bytes/482'), array(), $this->getOptions($options));
Expand Down

0 comments on commit 73e85cf

Please sign in to comment.