Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mikeal/request
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal committed Mar 15, 2013
2 parents 16b5ab9 + aa208cf commit 7d10c1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,15 +963,21 @@ Request.prototype.multipart = function (multipart) {
return self
}
Request.prototype.json = function (val) {
this.setHeader('accept', 'application/json')
var self = this;
var setAcceptHeader = function() {
if (!self.headers['accept'] && !self.headers['Accept']) {
self.setHeader('accept', 'application/json')
}
}
setAcceptHeader();
this._json = true
if (typeof val === 'boolean') {
if (typeof this.body === 'object') {
this.setHeader('content-type', 'application/json')
setAcceptHeader();
this.body = safeStringify(this.body)
}
} else {
this.setHeader('content-type', 'application/json')
setAcceptHeader();
this.body = safeStringify(val)
}
return this
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"url": "http://github.com/mikeal/request/issues"
},
"engines": [
"node >= 0.3.6"
"node >= 0.8.0"
],
"main": "index.js",
"dependencies": {
Expand Down

0 comments on commit 7d10c1e

Please sign in to comment.