Force download of Response body
@param  mixed $data Pass a falsy value to disable download, pass a filename for exporting content or array with raw string data
@return void
434127
public static function download($data){
        if (is_array($data)) {
            if (isset($data['filename'])) static::$force_dl = $data['filename'];
            if (isset($data['charset'])) static::charset($data['charset']);
            if (isset($data['mime'])) static::type($data['mime']);
            if (isset($data['body'])) static::body($data['body']);
        } else static::$force_dl = $data;
    }
883285
public function download($view, $data = [], $name = 'download')
    {
        $path = $this->processOutput($view, $data);

        return $this->responseDownload($path, $name);
    }
642193
protected function request($data) {
    try {
      if ($this->method == 'delete') {
        $response = $this->client->{$this->method}($this->path(), [], $data);
      }
      else {
        $response = $this->client->{$this->method}($this->path(), $data);
      }
      $this->client->close();
    }
    catch (\Exception $e) {
      // Throw an expection if something goes wrong.
      $this->triggerError($e->getMessage());
    }
    return $this->response($response);
  }
163072
public function setData($data = array())
    {
        /**
         * Since we base our signature off of the secure[data] parameter it cannot
         * be changed once the signature has been generated.
         */
        if (isset($this->requestSignature)) {
            throw new BadMethodCallException('The signature for this request has already been generated.');
        }

        $this->data = $data;
        $this->mergeRedirect();
    }
1125018
public function post($data)
    {
        $args = func_get_args();
        if(count($args) == 1) {
            $args = null;
        } else {
            $data = array_pop($args);
        }

        $response = '';

        try {
            $response = $this->client->request($this, 'post', $args, $data);
            return $response['data'];
        } catch (Exception $ex) {
            $this->dispatchException($ex);
        }

    }
222462
public function sendData($data)
    {
        $httpResponse = $this->sendRequest($data);

        $responseClass = $this->getResponseClassName();
        return $this->response = new $responseClass($this, $httpResponse);
    }
1273732
protected function doRequest($data)
    {
        try {
            $response = $this->client->request('POST', '', [
                'expect' => false,
                'body'   => $data
            ]);

            if ($response->getStatusCode() != 200) {
                throw new TransportException($response->getBody()->getContents() ?: 'Http request failed, status: '
                    .$response->getStatusCode(), TransportException::REMOTE);
            }
        } catch (TransportException $e) {
            throw $e;
        } catch (Throwable $e) {
            if ($this->causedByConnectionProblem($e)) {
                throw new TransportException($e->getMessage(), TransportException::CONNECTION, $e);
            }

            throw new TransportException($e->getMessage(), 0, $e);
        }

        return $response->getBody()->getContents();
    }
626483
public function addData($data) : void
    {
        Assert::isInstanceOfAny($data, [Chunk::class, X509Certificate::class]);
        $this->data[] = $data;
    }
1047281
protected static function sendCsv($data)
    {
        header("Content-Disposition: attachment; filename=".uniqid('dataExpl').'.csv');
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header("Content-Description: File Transfer");
        exit(Helper::arrayToCsv($data));
    }
11885
public function create($data)
    {
        $response = $this->restClient->post($this->endpoint, $data);
        return $response['body'];
    }
1280018
public function download($filename)
    {
        return $this->response->withFile($this->getPath($filename, false), ['download' => true]);
    }
734962
protected function wrapBody($data = '')
    {
        // HTTP
        if (false !== strpos($this->scheme, 'http')) {
            // Body
            $body = '';
            if (!empty($data)) {
                if (!in_array($this->method, ['GET', 'HEAD', 'OPTIONS'])) {
                    $body = Json::encode((array) $data);
                    $this->setHeader('Content-Length', strlen($body));
                    $this->setHeader('Content-Type', 'application/json');
                } else {
                    if (is_array($data)) {
                        $data = http_build_query($data);
                    }
                    $this->path .= (false === strpos($this->path, '?') ? '?' : '&') . $data;
                }
            }

            //Cookie
            $cookies = '';
            foreach ($this->cookies as $cookie) {
                $cookies .= $cookie->asString();
            }

            //Header
            $ua = static::USER_AGENT;
            $version = static::HTTP_VERSION;
            $header = "{$this->method} {$this->path} HTTP/{$version}\r\n";
            foreach ($this->headers as $key => $value) {
                $header .= "$key: " . (is_array($value) ? implode(',', $value) : $value) . "\r\n";
            }
            if (!empty($cookies)) {
                $header .= "Cookie: {$cookies}\r\n";
            }
            $header .= "Accept: application/json\r\n";
            $header .= "User-Agent: {$ua}\r\n";
            $header .= "\r\n";

            $data = $header . $body;
        } else {
            $body = [
                'method'  => $this->method,
                'path'    => $this->path,
                'headers' => $this->headers,
            ];
            if (!empty($data)) {
                $body['body'] = (array) $data;
            }
            $data = Json::encode($body);
        }

        return $data;
    }
501043
protected function setData($data = [])
    {
        if (!isset($data[self::RS_KEY_CODE])) {
            $data[self::RS_KEY_CODE] = 0;
        }
        if (!isset($data[self::RS_KEY_MSG])) {
            $data[self::RS_KEY_MSG] = 'Success';
        }
        if (!isset($data[self::RS_KEY_TYPE])) {
            $data[self::RS_KEY_TYPE] = self::RESPONSE_XHTML;
        }

        if (!isset($data[self::RS_KEY_DATA])) {
            $data[self::RS_KEY_DATA] = new \stdClass();
        } else {
            if (!$data instanceof \stdClass) {
                $data[self::RS_KEY_DATA] = new \stdClass();
            }
        }
        $this->data = $data;
    }
404855
public function sendData($data)
    {
        if (is_array($data) && count($data)) {
            $class = $this->getResponseClass();

            return $this->response = new $class($this, $data);
        }

        return false;
    }
940715
public function sendData($data)
    {
        $response = $this->gocardless->mandates()->update($data['mandateId'], $data['mandateData']);

        return $this->response = new MandateResponse($this, $response);
    }
1192805
public function parseContentLength($data)
    {
        $this->request->onData($data);
        $this->buffer.= $data;

        if (strlen($this->buffer) >= $this->contentLength) {
            $this->buffer = "";
            $this->notifyCompleted();
        }
    }
1136083
public function sync($data = null)
    {
        $this->insertToFlexiBee($data);
        $insertResult = $this->lastResponseCode;
        if ($insertResult == 201) {
            $this->reload();
        }
        $loadResult = $this->lastResponseCode;
        return ($insertResult + $loadResult) == 401;
    }