Skip to content

Commit

Permalink
allow for unicode characters in string payloads, closes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Aug 2, 2014
1 parent fa8d97f commit a3db17f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -33,7 +33,7 @@ exports.request = function (method, url, options, callback, _trace) {
(typeof options.payload === 'string' || Buffer.isBuffer(options.payload))) {

uri.headers = Hoek.clone(uri.headers) || {};
uri.headers['Content-Length'] = options.payload.length;
uri.headers['Content-Length'] = Buffer.isBuffer(options.payload) ? options.payload.length : Buffer.byteLength(options.payload);
}

if (options.rejectUnauthorized !== undefined && uri.protocol === 'https:') {
Expand Down
26 changes: 26 additions & 0 deletions test/index.js
Expand Up @@ -80,6 +80,32 @@ describe('Nipple', function () {
});
});

it('requests a POST resource with unicode characters in payload', function (done) {

var server = Http.createServer(function (req, res) {

expect(req.headers['content-length']).to.equal('14');
res.writeHead(200, { 'Content-Type': 'text/plain' });
req.pipe(res);
});

server.listen(0, function () {

var unicodePayload = JSON.stringify({ field: 'ć' });
Nipple.request('post', 'http://localhost:' + server.address().port, { payload: unicodePayload }, function (err, res) {

expect(err).to.not.exist;
Nipple.read(res, function (err, body) {

expect(err).to.not.exist;
expect(body.toString()).to.equal(unicodePayload);
server.close();
done();
});
});
});
});

it('requests a POST resource with headers', function (done) {

var server = Http.createServer(function (req, res) {
Expand Down

0 comments on commit a3db17f

Please sign in to comment.