-
Notifications
You must be signed in to change notification settings - Fork 282
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 #123 from alexindigo/v1.0.0-rc2
#109 Append proper line break
- Loading branch information
Showing
3 changed files
with
53 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
var http = require('http'); | ||
var common = require('../common'); | ||
var assert = common.assert; | ||
var FormData = require(common.dir.lib + '/form_data'); | ||
var server; | ||
|
||
function submitForm() { | ||
|
||
var form = new FormData(); | ||
|
||
form.append('field', 'value'); | ||
|
||
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(); | ||
}); | ||
} | ||
|
||
// create https server | ||
server = http.createServer(function(req, res) { | ||
|
||
var body = ''; | ||
|
||
req.setEncoding('utf8'); | ||
|
||
// old and simple | ||
req.on('data', function(data) { | ||
body += data; | ||
}); | ||
|
||
req.on('end', function() | ||
{ | ||
// last character(s) sequence equals predefined line break | ||
assert.strictEqual(body.substr(-1 * FormData.LINE_BREAK.length), FormData.LINE_BREAK); | ||
|
||
res.writeHead(200); | ||
res.end(); | ||
}); | ||
}); | ||
|
||
// when https server ready submit form | ||
server.listen(common.port, submitForm); |