summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElmer Thomas <elmer@thinkingserious.com>2016-06-10 17:47:24 -0700
committerElmer Thomas <elmer@thinkingserious.com>2016-06-10 17:47:24 -0700
commit01c3fc4b94df008cfe03ffb467d4c6dbe6dcfb2c (patch)
tree19c7727d4e826daca2f9ebe40aca4f99fa4135db
parentb57fed080d8e1ddec91b9a5ab50ad6faf8da8624 (diff)
downloadphp-http-client-01c3fc4b94df008cfe03ffb467d4c6dbe6dcfb2c.zip
php-http-client-01c3fc4b94df008cfe03ffb467d4c6dbe6dcfb2c.tar.gz
php-http-client-01c3fc4b94df008cfe03ffb467d4c6dbe6dcfb2c.tar.bz2
Version Bump v3.1.0: Automatically add Content-Type: application/json when there is a request bodyv3.1.0
-rw-r--r--CHANGELOG.md4
-rw-r--r--composer.json2
-rw-r--r--examples/example.php5
-rw-r--r--lib/SendGrid/Client.php8
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);