src/Uploadcare/Api.php
private function __setHeaders($ch, $add_headers = array(), $data = array())
    {
        $content_length = 0;
        $rawContent = '';
        if (count($data)) {
            $rawContent = utf8_encode(json_encode($data));
            $content_length = strlen($rawContent);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $rawContent);
        }

        // path
        $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
        $url_parts = parse_url($url);

        if ($url_parts === false) {
            throw new \Exception('Incorrect URL ' . $url);
        }

        $path = $url_parts['path'] . (!empty($url_parts['query']) ? '?' . $url_parts['query'] : '');

        // content
        $content_type = 'application/json';
        $content_md5 = md5($rawContent);

        // date
        $date = gmdate('D, d M Y H:i:s \G\M\T');

        // sign string
        $sign_string = join("\n", array(
            $this->current_method,
            $content_md5,
            $content_type,
            $date,
            $path,
        ));
        $sign_string_as_bytes = utf8_encode($sign_string);

        $secret_as_bytes = utf8_encode($this->secret_key);

        $sign = hash_hmac('sha1', $sign_string_as_bytes, $secret_as_bytes);

        $headers = array(
            sprintf('Host: %s', $this->api_host),
            sprintf('Authorization: Uploadcare %s:%s', $this->public_key, $sign),
            sprintf('Date: %s', $date),
            sprintf('Content-Type: %s', $content_type),
            sprintf('Content-Length: %d', $content_length),
            sprintf('Accept: application/vnd.uploadcare-v%s+json', $this->api_version),
            sprintf('User-Agent: %s', $this->getUserAgentHeader()),
        ) + $add_headers;

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_HEADER, 1);
    }
private function __setHeaders($ch, $add_headers = array(), $data = array())
    {
        $content_length = 0;
        $rawContent = '';
        if (count($data)) {
            $rawContent = utf8_encode(json_encode($data));
            $content_length = strlen($rawContent);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $rawContent);
        }

        // path
        $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
        $url_parts = parse_url($url);

        if ($url_parts === false) {
            throw new \Exception('Incorrect URL ' . $url);
        }

        $path = $url_parts['path'] . (!empty($url_parts['query']) ? '?' . $url_parts['query'] : '');

        // content
        $content_type = 'application/json';
        $content_md5 = md5($rawContent);

        // date
        $date = gmdate('D, d M Y H:i:s \G\M\T');

        // sign string
        $sign_string = join("\n", array(
            $this->current_method,
            $content_md5,
            $content_type,
            $date,
            $path,
        ));
        $sign_string_as_bytes = utf8_encode($sign_string);

        $secret_as_bytes = utf8_encode($this->secret_key);

        $sign = hash_hmac('sha1', $sign_string_as_bytes, $secret_as_bytes);

        $headers = array(
            sprintf('Host: %s', $this->api_host),
            sprintf('Authorization: Uploadcare %s:%s', $this->public_key, $sign),
            sprintf('Date: %s', $date),
            sprintf('Content-Type: %s', $content_type),
            sprintf('Content-Length: %d', $content_length),
            sprintf('Accept: application/vnd.uploadcare-v%s+json', $this->api_version),
            sprintf('User-Agent: %s', $this->getUserAgentHeader()),
        ) + $add_headers;

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_HEADER, 1);
    }
Set all the headers for request and set return transfer.

@param resource $ch. Curl resource.
@param array $add_headers additional headers.
@param array $data Data array.
@throws \Exception
@return void