diff options
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | composer.json | 2 | ||||
-rw-r--r-- | examples/example.php | 5 | ||||
-rw-r--r-- | lib/SendGrid/Client.php | 8 |
4 files changed, 11 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index c81d435..ab35ebb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [3.1.0] - 2016-06-10 +### Added +- Automatically add Content-Type: application/json when there is a request body + ## [3.0.0] - 2016-06-06 ### Changed - Made the Request and Response variables non-redundant. e.g. request.requestBody becomes request.body diff --git a/composer.json b/composer.json index 88d6761..8ca92eb 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "sendgrid/php-http-client", "description": "HTTP REST client, simplified for PHP", "type": "library", - "version": "3.0.0", + "version": "3.1.0", "require-dev": { "phpunit/phpunit": "~4.4", "squizlabs/php_codesniffer": "2.*" diff --git a/examples/example.php b/examples/example.php index 9e414eb..1eb8c41 100644 --- a/examples/example.php +++ b/examples/example.php @@ -6,10 +6,7 @@ include(dirname(__DIR__).'/lib/SendGrid/client.php'); // This gets the parent directory, for your current directory use getcwd() $path_to_config = dirname(__DIR__); $api_key = getenv('SENDGRID_API_KEY'); -$headers = array( - 'Content-Type: application/json', - 'Authorization: Bearer '.$api_key -); +$headers = array('Authorization: Bearer '.$api_key); $client = new SendGrid\Client('https://api.sendgrid.com', $headers, '/v3', null); // GET Collection diff --git a/lib/SendGrid/Client.php b/lib/SendGrid/Client.php index 860501c..e1fbad6 100644 --- a/lib/SendGrid/Client.php +++ b/lib/SendGrid/Client.php @@ -165,13 +165,15 @@ class Client curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($method)); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + if(isset($request_headers)) { + $this->request_headers = array_merge($this->request_headers, $request_headers); + } if(isset($request_body)) { $request_body = json_encode($request_body); curl_setopt($curl, CURLOPT_POSTFIELDS, $request_body); $content_length = array('Content-Length: ' . strlen($request_body)); - } - if(isset($request_headers)) { - $this->request_headers = array_merge($this->request_headers, $request_headers); + $content_type = array('Content-Type: application/json'); + $this->request_headers = array_merge($this->request_headers, $content_type); } curl_setopt($curl, CURLOPT_HTTPHEADER, $this->request_headers); $curl_response = curl_exec($curl); |