/** * Collect data as it's received * * @since 1.6.1 * * @param resource $handle cURL resource * @param string $data Body data * @return integer Length of provided data */ protected function stream_body($handle, $data) { $this->hooks->dispatch('request.progress', array($data, $this->response_bytes, $this->response_byte_limit)); $data_length = strlen($data); // Are we limiting the response size? if ($this->response_byte_limit) { if ($this->response_bytes === $this->response_byte_limit) { // Already at maximum, move on return $data_length; } if ($this->response_bytes + $data_length > $this->response_byte_limit) { // Limit the length $limited_length = $this->response_byte_limit - $this->response_bytes; $data = substr($data, 0, $limited_length); } } if ($this->stream_handle) { fwrite($this->stream_handle, $data); } else { $this->response_data .= $data; } $this->response_bytes += strlen($data); return $data_length; }
/** * Dispatch a Requests hook to a native WordPress action. * * @param string $hook Hook name. * @param array $parameters Parameters to pass to callbacks. * @return boolean True if hooks were run, false if nothing was hooked. */ public function dispatch($hook, $parameters = array()) { $result = parent::dispatch($hook, $parameters); // Handle back-compat actions switch ($hook) { case 'curl.before_send': /** This action is documented in wp-includes/class-wp-http-curl.php */ do_action_ref_array('http_api_curl', array($parameters[0], $this->request, $this->url)); break; } /** * Transforms a native Request hook to a WordPress actions. * * This action maps Requests internal hook to a native WordPress action. * * @see https://github.com/rmccue/Requests/blob/master/docs/hooks.md * * @param array $parameters Parameters from Requests internal hook. * @param array $request Request data in WP_Http format. * @param string $url URL to request. */ do_action_ref_array("requests-{$hook}", $parameters, $this->request, $this->url); return $result; }