nodules / asker Goto Github PK
View Code? Open in Web Editor NEWhttp.request wrapper with gzip, request retries and http.Agent tuning
License: MIT License
http.request wrapper with gzip, request retries and http.Agent tuning
License: MIT License
nodeunit has some issues with async testing, that we found while creating tests for http.
if (acceptEncoding.indexOf('gzip') === -1) {
this.options.headers['accept-encoding'] = 'gzip, ' + acceptEncoding;
}
Update: issue title was "write tests for POST/PUT/PATCH/DELETE methods"
Update: issue title was "compile request body from query
option instead of body
"
should return null
Now only Object strigifying supported. Maybe there is the place for an option "requestEncoding" with possible values:
stringify
โ existing behaviour;urlencoded
multipart
options.timeout + self.QUEUE_TIMEOUT_DELTA
@kaero what do you think?
https://github.com/nodules/asker/blob/master/lib/asker.js#L104
Is it useful to have option to format body in querystring (and add header 'Content-type' 'application/x-www-form-urlencoded') if he gets typeof body == 'object' ?
http.globalAgent.maxSockets = 1024;
http.Agent.defaultMaxSockets = 1024;
{ method : 'post' } => request executed as post, but body not prepared in the constructor
Request.DEFAULT_OPTIONS = {
host : 'localhost',
port : 80,
path : '/',
method : 'GET',
maxRetries : 0,
timeout : 500,
allowGzip : true,
requestId : ''
};
so subsequent execute()
calls is allowed now.
var Request = require('asker'),
request = new Request();
produce unexpected error
TypeError: Cannot read property 'headers' of undefined
at new Request (/Users/kaero/work/asker/lib/asker.js:63:39)
first time callback called with args:
error : {
code: 905,
message: 'http.clientRequest error for request %requestId% in 1~2 ms localhost:10089/',
/*[Error: Parse Error]*/
originalError: {
bytesParsed: 110,
code: 'HPE_INVALID_CONSTANT'
}
},
response : undefined
second time:
error : null,
response : { /* response object with data striped to content-length */ }
if ( ! this.options.headers['content-length']) {
this.options.headers['content-length'] = Buffer.byteLength(this.options.body, 'utf8');
}
Looks like minor bug, but url 'yandex.com/index.html' parsed incorrectly due to protocol prefix 'http://' is absent. While asker supports HTTP only, passing protocol in the url may be optional.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.