Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #382 from wxt2005/custom-stream
Handle custom stream
- Loading branch information
Showing
5 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var common = require('../common'); | ||
var assert = common.assert; | ||
var http = require('http'); | ||
var FormData = require(common.dir.lib + '/form_data'); | ||
var Readable = require('stream').Readable; | ||
|
||
var server = http.createServer(function(req, res) { | ||
assert.strictEqual(req.headers['Content-Length'], undefined); | ||
res.writeHead(200); | ||
res.end('done'); | ||
}); | ||
|
||
server.listen(common.port, function() { | ||
var form = new FormData(); | ||
|
||
var util = require('util'); | ||
util.inherits(CustomReadable, Readable); | ||
|
||
/** | ||
* Custion readable constructor | ||
* @param {Object} opt options | ||
* @constructor | ||
*/ | ||
function CustomReadable(opt) { | ||
Readable.call(this, opt); | ||
this._max = 2; | ||
this._index = 1; | ||
} | ||
|
||
CustomReadable.prototype._read = function() { | ||
var i = this._index++; | ||
// console.error('send back read data'); | ||
if (i > this._max) { | ||
this.push(null); | ||
} else { | ||
this.push('' + i); | ||
} | ||
}; | ||
form.append('readable', new CustomReadable()); | ||
|
||
form.submit('http://localhost:' + common.port + '/', function(err, res) { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
assert.strictEqual(res.statusCode, 200); | ||
|
||
// unstuck new streams | ||
res.resume(); | ||
|
||
server.close(); | ||
}); | ||
|
||
}); |
Shouldn't this be
err.message
? I was just going through - we probably didn't need to do major version bump and I could do a patched release.