Comparing version 0.0.24 to 0.0.25
@@ -39,2 +39,5 @@ /* | ||
config.headers['Content-Type'] = "multipart/form-data;boundary=" + formData.getBoundary(); | ||
if (config.syncLength){ | ||
config.headers['Content-Length'] = formData.getLengthSync(); | ||
} | ||
return formData; | ||
@@ -41,0 +44,0 @@ }; |
@@ -48,2 +48,3 @@ /* | ||
(config.encoding ? config.encoding : 'utf-8'); | ||
config.headers['Content-Length'] = buffer.length; | ||
logger.trace('pack urlencode data succ ServiceID=' + config.serviceID + ' data=' + buffer); | ||
@@ -50,0 +51,0 @@ return buffer; |
@@ -103,3 +103,11 @@ /* | ||
timer.end('request'); | ||
me.emit('data', data); | ||
if (conf.catchCallback){ | ||
try{ | ||
me.emit('data', data); | ||
}catch (err){ | ||
onError(err); | ||
} | ||
}else{ | ||
me.emit('data', data); | ||
} | ||
logger.notice('request end ' + ralUtil.qs(me.getLogInfo())); | ||
@@ -106,0 +114,0 @@ } |
{ | ||
"name": "node-ral", | ||
"version": "0.0.24", | ||
"version": "0.0.25", | ||
"description": "a rpc client for node", | ||
"main": "index.js", | ||
"scripts": { | ||
"publish": "npm publish --registry=http://registry.npmjs.org", | ||
"pub": "npm publish --registry=http://registry.npmjs.org", | ||
"test": "mocha --reporter dot --check-leaks test/", | ||
@@ -9,0 +9,0 @@ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", |
@@ -41,3 +41,3 @@ node-ral | ||
pack: 'form', | ||
method: 'POST' | ||
method: 'POST', | ||
encoding: 'gbk', | ||
@@ -62,3 +62,3 @@ balance: 'random', | ||
"pack": "form", | ||
"method": "POST" | ||
"method": "POST", | ||
"encoding": "gbk", | ||
@@ -107,3 +107,4 @@ "balance": "random", | ||
- [X] FormData | ||
- [X] Stream | ||
- Protocol | ||
- [X] HTTP | ||
- [X] HTTP |
@@ -14,2 +14,3 @@ /* | ||
var FormDataConverter = require('../lib/ext/converter/formDataConverter.js'); | ||
var StreamConverter = require('../lib/ext/converter/streamConverter.js'); | ||
var HttpProtocol = require('../lib/ext/protocol/httpProtocol.js'); | ||
@@ -24,2 +25,3 @@ var FormConverter = require('../lib/ext/converter/fromConverter.js'); | ||
var post_test = require('./protocol/http_protocol_post_test.js'); | ||
var FormData = require('form-data'); | ||
@@ -248,2 +250,16 @@ var mockUTF8Context = { | ||
}); | ||
it('syncLength should send content-length', function () { | ||
var converter = new FormDataConverter(); | ||
var data = { | ||
name: '张三李四' | ||
}; | ||
var options = _.clone(mockUTF8Context); | ||
options.syncLength = true; | ||
var httpProtocol = new HttpProtocol(); | ||
util.merge(options, post_test.service); | ||
options = HttpProtocol.normalizeConfig(options); | ||
var pack = converter.pack(options, data); | ||
options.headers['Content-Length'].should.be.eql(169); | ||
}); | ||
}); | ||
@@ -375,2 +391,42 @@ | ||
}); | ||
}); | ||
}); | ||
describe('stream converter', function () { | ||
it('has right name', function () { | ||
var converter = new StreamConverter(); | ||
converter.getName().should.be.equal('stream'); | ||
}); | ||
it('has right catagory', function () { | ||
var converter = new StreamConverter(); | ||
converter.getCategory().should.be.equal('converter'); | ||
}); | ||
it('pack should work fine', function (done) { | ||
var converter = new StreamConverter(); | ||
var form = new FormData(); | ||
form.append('name', '张三李四'); | ||
var options = _.clone(mockUTF8Context); | ||
var httpProtocol = new HttpProtocol(); | ||
var server = post_test.createServer(); | ||
util.merge(options, post_test.service); | ||
options = HttpProtocol.normalizeConfig(options); | ||
var pack = converter.pack(options, form); | ||
util.merge(options, { | ||
server: post_test.request.server | ||
}); | ||
options.headers = {}; | ||
options.headers['Content-Type'] = "multipart/form-data;boundary=" + form.getBoundary(); | ||
var request = httpProtocol.talk(options, function(res){ | ||
res.on('data', function (data) { | ||
server.close(); | ||
data.toString().should.be.equal('hear you 张三李四'); | ||
done(); | ||
}); | ||
res.on('error', function(){ | ||
server.close(); | ||
}); | ||
}); | ||
pack.pipe(request); | ||
}); | ||
}); |
@@ -134,3 +134,3 @@ /* | ||
it.only('should work well with https', function(done) { | ||
it('should work well with https', function(done) { | ||
var get_test = require('./protocol/http_protocol_get_test.js'); | ||
@@ -137,0 +137,0 @@ //start a http server for get |
@@ -56,6 +56,6 @@ /* | ||
method: 'GET', | ||
path: '/v2/?login', | ||
path: '/', | ||
rejectUnauthorized: false, | ||
server : { | ||
host : 'passport.baidu.com', | ||
host : 'travis-ci.org', | ||
port: 443 | ||
@@ -62,0 +62,0 @@ } |
@@ -285,2 +285,18 @@ /* | ||
}); | ||
it('should catch onData error when catchCallback is true', function (done) { | ||
before(function( ok ){ | ||
isInited.on('done', ok); | ||
}); | ||
var req = RAL('GET_QS_SERV', { | ||
catchCallback: true | ||
}); | ||
req.on('data', function(data){ | ||
throw new Error('lalala'); | ||
}); | ||
req.on('error', function(err){ | ||
err.message.should.be.match(/lalal/); | ||
done(); | ||
}); | ||
}); | ||
}); |
260142
61
7093
108