From 2ab5938086b07f2a28c145bafd5343a2872faa3c Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Fri, 10 Jun 2016 20:01:14 -0700 Subject: [PATCH] Version Bump v2.2.0: Automatically add Content-Type: application/json when there is a request body --- CHANGELOG.md | 4 ++++ examples/example.js | 1 - lib/client.js | 1 + package.json | 2 +- test/test.js | 4 ++-- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1523c8d..36517ba 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/). +## [2.2.0] - 2016-06-10 +### Added +- Automatically add Content-Type: application/json when there is a request body + ## [2.1.0] - 2016-06-08 ### Added - Cleaner request object initialization diff --git a/examples/example.js b/examples/example.js index 8553ac0..0ec49de 100644 --- a/examples/example.js +++ b/examples/example.js @@ -3,7 +3,6 @@ var Client = require('../lib/client.js').Client // These values persist across of subsequent calls, unless overidden. var globalRequest = require('../lib/client.js').emptyRequest globalRequest.host = 'api.sendgrid.com'; -globalRequest.headers['Content-Type'] = 'application/json' // You must add your SendGrid API Key to your OS Environment globalRequest.headers['Authorization'] = 'Bearer '.concat(process.env.SENDGRID_API_KEY) var client = new Client(globalRequest) diff --git a/lib/client.js b/lib/client.js index bb1176e..5fe49f7 100644 --- a/lib/client.js +++ b/lib/client.js @@ -74,6 +74,7 @@ function Client (globalRequest) { if (!isEmpty(endpointRequest.body)) { body = JSON.stringify(endpointRequest.body) request.headers['Content-Length'] = body.length + request.headers['Content-Type'] = 'application/json' } return request diff --git a/package.json b/package.json index fb91e0b..763b2e1 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ ], "name": "sendgrid-rest", "description": "HTTP REST client, simplified for Node.js.", - "version": "2.1.0", + "version": "2.2.0", "homepage": "https://sendgrid.com", "repository": { "type": "git", diff --git a/test/test.js b/test/test.js index 3e2f090..439f211 100644 --- a/test/test.js +++ b/test/test.js @@ -65,8 +65,8 @@ describe('Client', function () { '/test?limit=100&offset=0', 'path equal to /test?limit=100&offset=0') assert.equal(JSON.stringify(JSON.parse(response.body).headers), - '{"x-test":"test","content-length":20,"host":"api.test.com"}', - 'headers equal {"x-test":"test","content-length":20,"host":"api.test.com"}') + '{"x-test":"test","content-length":20,"content-type":"application/json","host":"api.test.com"}', + 'headers equal {"x-test":"test","content-length":20,"content-type":"application/json","host":"api.test.com"}') assert.equal(JSON.stringify(response.headers), '{"content-type":"application/json"}', 'response.headers equal {"content-type":"application/json"}')