Skip to content

Commit

Permalink
updated filestack source headers
Browse files Browse the repository at this point in the history
  • Loading branch information
hueyl77 committed May 31, 2017
1 parent 948041e commit c2c9d52
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions filestack/mixins/CommonMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ trait CommonMixin
{
protected $http_client;
protected $http_promises;

protected $user_agent_header;
protected $source_header;

/**
Expand Down Expand Up @@ -418,14 +420,29 @@ protected function sendRequest($method, $url, $data = [], $headers = [])
/**
* Get source header
*/
protected function getSourceHeader()
protected function getSourceHeaders()
{
if (!$this->source_header) {
$headers = [];

if (!$this->user_agent_header || !$this->source_header) {
$version = trim(file_get_contents(__DIR__ . '/../../VERSION'));
$this->source_header = sprintf('filestack-php-%s',
$version);

if (!$this->user_agent_header) {
$this->user_agent_header = sprintf('filestack-php-%s',
$version);
}

if (!$this->source_header) {
$this->source_header = sprintf('PHP-%s',
$version);
}
}
return $this->source_header;

$headers['user-agent'] = $this->user_agent_header;
$headers['filestack-source'] = $this->source_header;

//user_agent_header
return $headers;
}

/**
Expand All @@ -446,9 +463,9 @@ protected function multipartGetChunk($filepath, $seek_point) {
*/
protected function addRequestSourceHeader(&$headers)
{
$source_header = $this->getSourceHeader();
$headers['User-Agent'] = $source_header;
$headers['Filestack-Source'] = $source_header;
$source_headers = $this->getSourceHeaders();
$headers['User-Agent'] = $source_headers['user-agent'];
$headers['Filestack-Source'] = $source_headers['filestack-source'];
}

/**
Expand Down

0 comments on commit c2c9d52

Please sign in to comment.