Comparing version 0.1.0 to 0.1.1
19
index.js
@@ -217,8 +217,16 @@ /** | ||
if (is(data).a(Object)) { | ||
$this.options.json = true; | ||
if (!type || type != 'application/json') { | ||
$this.type('form'); | ||
if ($this.options.body && is($this.options.body).a(Object)) { | ||
for (var key in data) $this.options.body[key] = data[key]; | ||
} else { | ||
$this.options.body = data; | ||
type = $this._headers['content-type']; | ||
$this.options.body = Unirest.serializers.form(data); | ||
} else if (type == 'application/json') { | ||
$this.options.json = true; | ||
if ($this.options.body && is($this.options.body).a(Object)) { | ||
for (var key in data) $this.options.body[key] = data[key]; | ||
} else { | ||
$this.options.body = data; | ||
} | ||
} | ||
@@ -228,2 +236,3 @@ } else if (is(data).a(String)) { | ||
$this.type('form'); | ||
type = $this._headers['content-type']; | ||
@@ -230,0 +239,0 @@ } |
{ | ||
"name": "unirest", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Lightweight HTTP Request library.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -254,2 +254,3 @@ # Unirest for Node.js [![Build Status](https://travis-ci.org/Mashape/unirest-nodejs.png?branch=master)](https://travis-ci.org/Mashape/unirest-nodejs) | ||
unirest.post('http://httpbin.org/post') | ||
.type('json') | ||
.send({ | ||
@@ -256,0 +257,0 @@ foo: 'bar', |
@@ -56,7 +56,7 @@ var should = require("should"); | ||
describe('POST request', function () { | ||
it('should correctly post JSON data.', function (done) { | ||
it('should correctly post FORM data.', function (done) { | ||
var data = { | ||
hello: 'world', | ||
is: 'unirest', | ||
my: 'name', | ||
is: 'unirest' | ||
hello: 'world' | ||
}; | ||
@@ -66,3 +66,19 @@ | ||
should(response.status).equal(200); | ||
should(response.body.data).equal(JSON.stringify(data)); | ||
should(response.body.form).have.type('object'); | ||
should(response.body.headers['Content-Length']).equal('30'); | ||
should(response.body.headers['Content-Type']).equal('application/x-www-form-urlencoded'); | ||
done(); | ||
}); | ||
}); | ||
it('should correctly post JSON data.', function (done) { | ||
var data = { | ||
is: 'unirest', | ||
my: 'name', | ||
hello: 'world' | ||
}; | ||
unirest.post('http://httpbin.org/post').header('content-type', 'application/json').send(data).end(function (response) { | ||
should(response.status).equal(200); | ||
should(response.body.data).have.type('string'); | ||
should(response.body.headers['Content-Type']).equal('application/json'); | ||
@@ -73,2 +89,3 @@ done(); | ||
it('should check for buffers', function (done) { | ||
@@ -83,19 +100,3 @@ unirest.post('http://httpbin.org/post') | ||
}); | ||
it('should correctly post FORM data.', function (done) { | ||
var data = unirest.serializers.form({ | ||
hello: 'world', | ||
my: 'name', | ||
is: 'unirest' | ||
}); | ||
unirest.post('http://httpbin.org/post').send(data).end(function (response) { | ||
should(response.status).equal(200); | ||
should(response.body.form).have.type('object'); | ||
should(response.body.headers['Content-Length']).equal('30'); | ||
should(response.body.headers['Content-Type']).equal('application/x-www-form-urlencoded'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45835
775
656