Skip to content

Commit 54e2631

Browse files
committed
Merge pull request #14 from tagged/headerfix
Adds content-type header to API requests.
2 parents 38fed34 + 980513e commit 54e2631

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

lib/http_adapter/angular.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
AngularAdapter.prototype.post = function(req) {
1717
var headers = {
1818
'x-tagged-client-id': req.clientId,
19-
'x-tagged-client-url': this._$window.location
19+
'x-tagged-client-url': this._$window.location,
20+
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
2021
};
2122
return this._$http.post(req.url, req.body, {
2223
timeout: 10000,

lib/http_adapter/node.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Http.prototype.post = function(req) {
99
var headers = {
1010
Cookie: req.cookies || {},
1111
'x-tagged-client-id': req.clientId,
12-
'x-tagged-client-secret': req.secret
12+
'x-tagged-client-secret': req.secret,
13+
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
1314
};
1415

1516
return this._request.postAsync({

test/unit/lib/http_adapter/angular_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ describe('Angular Adapter', function() {
8181
this.$http.post.lastCall.args[2].headers['x-tagged-client-id'].should.equal(clientId);
8282
this.$http.post.lastCall.args[2].headers['x-tagged-client-url'].should.equal(location);
8383
});
84+
85+
it('sets content-type header', function() {
86+
var url = 'http://example.com/foo';
87+
var body = 'post body';
88+
var expectedContentType = 'application/x-www-form-urlencoded; charset=UTF-8';
89+
this.adapter.post({
90+
url: url,
91+
body: body
92+
});
93+
this.$http.post.calledOnce.should.be.true;
94+
this.$http.post.lastCall.args[2].headers.should.have.property('Content-Type', expectedContentType);
95+
});
8496
});
8597

8698
describe('getSessionToken', function() {

test/unit/lib/http_adapter/node_test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ describe('Node HTTP Adapter', function() {
7070
this.request.post.lastCall.args[0].headers.should.have.property('x-tagged-client-secret', clientSecret);
7171
});
7272

73+
it('sets content-type header', function() {
74+
var expectedContentType = 'application/x-www-form-urlencoded; charset=UTF-8';
75+
var url = 'http://example.com/foo';
76+
var body = 'post body';
77+
this.http.post({
78+
url: url,
79+
body: body
80+
});
81+
this.request.post.calledOnce.should.be.true;
82+
this.request.post.lastCall.args[0].should.have.property('headers');
83+
this.request.post.lastCall.args[0].headers.should.have.property('Content-Type', expectedContentType);
84+
});
85+
7386
it('resolves with response', function() {
7487
var expectedBody = 'expected body';
7588
var result = this.http.post({

0 commit comments

Comments
 (0)