Skip to content

Commit 01c3fc4

Browse files
Version Bump v3.1.0: Automatically add Content-Type: application/json when there is a request body
1 parent b57fed0 commit 01c3fc4

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [3.1.0] - 2016-06-10
7+
### Added
8+
- Automatically add Content-Type: application/json when there is a request body
9+
610
## [3.0.0] - 2016-06-06
711
### Changed
812
- Made the Request and Response variables non-redundant. e.g. request.requestBody becomes request.body

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sendgrid/php-http-client",
33
"description": "HTTP REST client, simplified for PHP",
44
"type": "library",
5-
"version": "3.0.0",
5+
"version": "3.1.0",
66
"require-dev": {
77
"phpunit/phpunit": "~4.4",
88
"squizlabs/php_codesniffer": "2.*"

examples/example.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
// This gets the parent directory, for your current directory use getcwd()
77
$path_to_config = dirname(__DIR__);
88
$api_key = getenv('SENDGRID_API_KEY');
9-
$headers = array(
10-
'Content-Type: application/json',
11-
'Authorization: Bearer '.$api_key
12-
);
9+
$headers = array('Authorization: Bearer '.$api_key);
1310
$client = new SendGrid\Client('https://api.sendgrid.com', $headers, '/v3', null);
1411

1512
// GET Collection

lib/SendGrid/Client.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,15 @@ public function makeRequest($method, $url, $request_body = null, $request_header
165165
curl_setopt($curl, CURLOPT_HEADER, 1);
166166
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
167167
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
168+
if(isset($request_headers)) {
169+
$this->request_headers = array_merge($this->request_headers, $request_headers);
170+
}
168171
if(isset($request_body)) {
169172
$request_body = json_encode($request_body);
170173
curl_setopt($curl, CURLOPT_POSTFIELDS, $request_body);
171174
$content_length = array('Content-Length: ' . strlen($request_body));
172-
}
173-
if(isset($request_headers)) {
174-
$this->request_headers = array_merge($this->request_headers, $request_headers);
175+
$content_type = array('Content-Type: application/json');
176+
$this->request_headers = array_merge($this->request_headers, $content_type);
175177
}
176178
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->request_headers);
177179
$curl_response = curl_exec($curl);

0 commit comments

Comments
 (0)