Skip to content

Commit

Permalink
Merge pull request #106 from Lyimmi/master
Browse files Browse the repository at this point in the history
Add option for request compression
  • Loading branch information
alexpechkarev authored Jul 20, 2022
2 parents 111968e + 1c34d17 commit 0d07b42
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/WebService.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ class WebService{
*/
protected $connectionTimeout;

/*
|--------------------------------------------------------------------------
| Request's compression setting
|--------------------------------------------------------------------------
|
|
|
*/
protected $requestUseCompression;

/**
* Setting endpoint
* @param string $key
Expand Down Expand Up @@ -264,6 +274,8 @@ protected function build( $service ){
// set the maximum time the transfer is allowed to complete
$this->requestTimeout = Config::get("googlemaps.request_timeout");

// set the compression flag
$this->requestUseCompression = Config::get("googlemaps.request_use_compression");

$this->clearParameters();
}
Expand Down Expand Up @@ -332,7 +344,7 @@ protected function getResponse(){
/**
* Make cURL request to given URL
* @param boolean $isPost
* @return object
* @return bool|string
* @throws \ErrorException
*/
protected function make( $isPost = false ){
Expand All @@ -351,6 +363,10 @@ protected function make( $isPost = false ){
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

if ($this->requestUseCompression) {
curl_setopt($ch, CURLOPT_ENCODING, "");
}

$output = curl_exec($ch);

if( $output === false ){
Expand Down
13 changes: 13 additions & 0 deletions src/config/googlemaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@
*/
'request_timeout' => 30,

/*
|--------------------------------------------------------------------------
| CURL's CURLOPT_ENCODING
|--------------------------------------------------------------------------
|
| Will be used for all web services to use compression on requests.
|
| Sets the contents of the "Accept-Encoding:" header a containing all
| supported encoding types.
|
*/
'request_use_compression' => false,

/*
|--------------------------------------------------------------------------
| Service URL
Expand Down

0 comments on commit 0d07b42

Please sign in to comment.