tjatse / req-fast Goto Github PK
View Code? Open in Web Editor NEWFastest way to fetch the web content(HTML stream) from server, supports:redirects, auto decode(e.g.:Chinese), gzip, cookie, proxy...
License: Apache License 2.0
Fastest way to fetch the web content(HTML stream) from server, supports:redirects, auto decode(e.g.:Chinese), gzip, cookie, proxy...
License: Apache License 2.0
While trying to download web pages, I ocasionally get this error.
URL = http://www.amulet.cz/doplnky/
C:\Users\sladg\Documents\Bohemian.studio\Crawler_4\node_modules\req-fast\lib\req_stream.js:257
this._data.request._aborted = true
^TypeError: Cannot set property '_aborted' of undefined
at RequestStream.abort (C:\Users\sladg\Documents\Bohemian.studio\Crawler_4\node_modules\req-fast\lib\req_stream.js:257:31)
at Object.onceWrapper (events.js:293:19)
at emitNone (events.js:86:13)
at ClientRequest.emit (events.js:188:7)
at Socket.emitRequestTimeout (_http_client.js:614:42)
at Object.onceWrapper (events.js:293:19)
at emitNone (events.js:91:20)
at Socket.emit (events.js:188:7)
at Socket._onTimeout (net.js:351:8)
at ontimeout (timers.js:386:14)`
Code responsible for this (req-fast/lib/req-stream.js line:250)
RequestStream.prototype.abort = function () {
debug('FORCE ABORT!!!')
try {
this._data.request && this._data.request.abort()
} catch (err) {
debug.enabled && debug('-> failed due to %s', err.toString())
}
this._data.request._aborted = true // right here.
this.emit('abort')
}
Fix:
I can understand that my solution is kind of ,,not-proper'', but it did the trick:
RequestStream.prototype.abort = function () {
debug('FORCE ABORT!!!')
try {
this._data.request && this._data.request.abort()
} catch (err) {
debug.enabled && debug('-> failed due to %s', err.toString())
}
if (this._data === undefined) {
this._data = ''
}
if (this._data.request === undefined) {
this._data.request = ''
}
this._data.request._aborted = true
this.emit('abort')
}
Hi,
I just updated to the latest version, because I was getting an error like :
unexpected end of file at Zlib._handle.onerror
which you just fixed, and now I am getting the following error using req-fast (in fact it's using read-art, which is using req-fast :)) :
/Users/jeremie/Documents/Workspace/AAA/Apps/aaa/node_modules/req-fast/lib/req_stream.js:117
if (this._unzip) {
^
TypeError: Cannot read property '_unzip' of undefined
at shouldContinue (/Users/jeremie/Documents/Workspace/AAA/Apps/aaa/node_modules/req-fast/lib/req_stream.js:117:19)
at RequestStream.onEnd (/Users/jeremie/Documents/Workspace/AAA/Apps/aaa/node_modules/req-fast/lib/req_stream.js:163:14)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at doNTCallback2 (node.js:452:9)
at process._tickCallback (node.js:366:17)
Program node bin/www exited with code 1
Hi,
I believe it's a mistake in either the doc / code:
A simple POST request like this doesn't work:
req({ url: queueUrl, headers: { 'Content-Type': 'text/xml' }, method: 'POST', data:
asdfasdfasdfasdf}, ....
And the reason is due to "data" is not a valid property for options.
Seems like you're using "_data" for the options.
After i changed to use "_data", it works flawlessly.
When I send post data, the server receive nothing but if I send with method get, the data is there...
req({ url : 'http://www.com', method: 'POST', data: { nickname : nickname }, dataType: 'json' }, function(error, response) { console.log(response); });
ERROR in ./~/tunnel2/lib/tunnel.js
Module not found: Error: Cannot resolve module 'net' in /web/sites/tripora/node_modules/tunnel2/lib
@ ./~/tunnel2/lib/tunnel.js 3:10-24
ERROR in ./~/tunnel2/lib/tunnel.js
Module not found: Error: Cannot resolve module 'tls' in /web/sites/tripora/node_modules/tunnel2/lib
@ ./~/tunnel2/lib/tunnel.js 4:10-24
ERROR in ./~/iconv-lite/encodings/tables/gb18030-ranges.json
Module parse failed: /web/sites/tripora/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json Unexpected token (1:9)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (1:9)
at Parser.pp$4.raise (/web/sites/tripora/node_modu```
ERROR in ./~/tunnel2/lib/tunnel.js
Module not found: Error: Cannot resolve module 'net' in /web/sites/example/node_modules/tunnel2/lib
@ ./~/tunnel2/lib/tunnel.js 3:10-24
ERROR in ./~/tunnel2/lib/tunnel.js
Module not found: Error: Cannot resolve module 'tls' in /web/sites/example/node_modules/tunnel2/lib
@ ./~/tunnel2/lib/tunnel.js 4:10-24
ERROR in ./~/iconv-lite/encodings/tables/gb18030-ranges.json
Module parse failed: /web/sites/example/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json Unexpected token (1:9)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (1:9)
at Parser.pp$4.raise (/web/sites/example/node_modules/webpack/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp.unexpected (/web/sites/example/node_modules/webpack/node_modules/acorn/dist/acorn.js:603:10)
at Parser.pp.semicolon (/web/sites/example/node_modules/webpack/node_modules/acorn/dist/acorn.js:581:61)
at Parser.pp$1.parseExpressionStatement (/web/sites/example/node_modules/webpack/node_modules/acorn/dist/acorn.js:966:10)
at Parser.pp$1.parseStatement (/web/sites/example/node_modules/webpack/node_modules/acorn/dist/acorn.js:730:24)
at Parser.pp$1.parseBlock (/web/sites/example/node_modules/webpack/node_modules/acorn/dist/acorn.js:981:25)
at Parser.pp$1.parseStatement (/web/sites/example/node_modules/webpack/node_modules/acorn/dist/acorn.js:709:33)
at Parser.pp$1.parseTopLevel (/web/sites/example/node_modules/webpack/node_modules/acorn/dist/acorn.js:638:25)
at Parser.parse (/web/sites/example/node_modules/webpack/node_modules/acorn/dist/acorn.js:516:17)
at Object.parse (/web/sites/example/node_modules/webpack/node_modules/acorn/dist/acorn.js:3098:39)
@ ./~/iconv-lite/encodings/dbcs-data.js 99:37-76
```les/webpack/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp.unexpected (/web/sites/tripora/node_modules/webpack/node_modules/acorn/dist/acorn.js:603:10)
at Parser.pp.semicolon (/web/sites/tripora/node_modules/webpack/node_modules/acorn/dist/acorn.js:581:61)
at Parser.pp$1.parseExpressionStatement (/web/sites/tripora/node_modules/webpack/node_modules/acorn/dist/acorn.js:966:10)
at Parser.pp$1.parseStatement (/web/sites/tripora/node_modules/webpack/node_modules/acorn/dist/acorn.js:730:24)
at Parser.pp$1.parseBlock (/web/sites/tripora/node_modules/webpack/node_modules/acorn/dist/acorn.js:981:25)
at Parser.pp$1.parseStatement (/web/sites/tripora/node_modules/webpack/node_modules/acorn/dist/acorn.js:709:33)
at Parser.pp$1.parseTopLevel (/web/sites/tripora/node_modules/webpack/node_modules/acorn/dist/acorn.js:638:25)
at Parser.parse (/web/sites/tripora/node_modules/webpack/node_modules/acorn/dist/acorn.js:516:17)
at Object.parse (/web/sites/tripora/node_modules/webpack/node_modules/acorn/dist/acorn.js:3098:39)
@ ./~/iconv-lite/encodings/dbcs-data.js 99:37-76
Hi,
how we can set rate limitation option a request? Because I've got Too Many Request error in my script I have to set this limitation.
Hi, thanks for all of your works, many of your library is helpful.
I just tried req-fast but it's do not follow permanent redirect (301).
Is this expected behaviors?
var req = require('req-fast');
req({
url: 'http://dentistvschef.wordpress.com/2013/01/16/japanese-spring-onionscallionleek-pancake-ala-dentist-chef/'
}, function(err, res){
console.log(res.body);
});
Thanks
The server has "Content-Encoding: deflate" response header, and the response is raw deflate encoded content.
Browsers can parse the url correctly(Firefox&Chromium).
Checked the code, it's not an easy change to recover from inflate error(when error, we can try inflate using zlib.createInflateRaw) or maybe we can remove the deflate part in accept encoding request header(request library only sends "gzip").
This is error I got:
buffer.js:503
throw new Error('"toString()" failed');
^Error: "toString()" failed
at Buffer.toString (buffer.js:503:11)
at RequestStream. (/home/adminvm/crawler/custom_modules/req-fast/lib/req.js:91:29)
at emitNone (events.js:86:13)
at RequestStream.emit (events.js:188:7)
at RequestStream.onEnd (/home/adminvm/crawler/custom_modules/req-fast/lib/req_stream.js:241:10)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
According to this thread: https://github.com/nodejs/node/issues/3175
This occurs when buffer exceed maximal length (268435440).
Code responsible:
/lib/req.js (line:91)
if (typeof resp.body !== 'string') {
resp.body = resp.body.toString()
}
So I would recommend putting some function, which divides code to smaller parts and after .toString(), it puts them together.
I fixed it by simple:
if (resp.body.length > 265000000) {
resp.body = ''
}
But it is suitable just in case you do not care about 1 page in thousands.
Hi @Tjatse
I plan to ditch the request
lib for all of my new projects, and i felt your req-fast
could be the answer that i have been looking for (it's simple and to the point, and deserve more stars).
Today i have a problem uploading file to a site which uses REST API which use POST
multipart/form-data
as just like any HTML form do.
I know i can do it using request
module, but i just wonder if it's possible with req-fast
, since i don't want to require both request
and req-fast
as it's a module for similar task.
If you can write the code while not sacrifice any speed / lightness of req-fast
, i think this should be at least included in req-fast
as uploading file is a very common issue.
What do you think about this?
Thank you
Upon an error the callback error argument just contains the status code and a standard response.
Is there anyway to get other details like the response headers and everything else?
Hi there,
I have an issue with req-fast here:
Could you help me resolve it?
Thanks,
Dong
req.js
90 if (typeof resp.body !== 'string') {
91 resp.body = resp.body.toString()
92 }
90 if (typeof resp.body !== 'string' && "add resp.header.encoding" ) {
91 resp.body = resp.body.toString()
92 }
If response data encoding is binary, I can't take it as a buffer and write it to a file. ใ ใ
I am not sure if this is normal or expected, but it seems that on error, both abort and error gets called. In my use case, I have manual aborts which I do wish to be able to keep track of (versus errors causing aborts).
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.