[Pkg-javascript-commits] [node-stream-http] 176/208: Avoid passing undefined to `xhr.send()`

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 13 13:39:42 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stream-http.

commit 8df10e0d653942ed4ecf899b2cbd0685dc8cf807
Author: John Hiesey <john at hiesey.com>
Date:   Mon Jan 16 01:52:34 2017 -0800

    Avoid passing undefined to `xhr.send()`
    
    Provides a more elegant fix to #67
---
 lib/request.js         |  2 +-
 test/browser/delete.js | 29 +++++++++++++++++++++++++++++
 test/server/index.js   | 18 ++++++++++++++++++
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/lib/request.js b/lib/request.js
index b3f44f7..7d26d0b 100644
--- a/lib/request.js
+++ b/lib/request.js
@@ -98,7 +98,7 @@ ClientRequest.prototype._onFinish = function () {
 	var opts = self._opts
 
 	var headersObj = self._headers
-	var body
+	var body = null
 	if (opts.method === 'POST' || opts.method === 'PUT' || opts.method === 'PATCH' || opts.method === 'MERGE') {
 		if (capability.blobConstructor) {
 			body = new global.Blob(self._body.map(function (buffer) {
diff --git a/test/browser/delete.js b/test/browser/delete.js
new file mode 100644
index 0000000..1ac073d
--- /dev/null
+++ b/test/browser/delete.js
@@ -0,0 +1,29 @@
+var Buffer = require('buffer').Buffer
+var fs = require('fs')
+var test = require('tape')
+
+var http = require('../..')
+
+var reference = fs.readFileSync(__dirname + '/../server/static/basic.txt')
+
+test('delete empty', function (t) {
+	var req = http.request({
+		path: '/verifyEmpty',
+		method: 'DELETE'
+	}, function (res) {
+		var buffers = []
+
+		res.on('end', function () {
+			console.log(Buffer.concat(buffers).toString('utf8'))
+			t.ok(Buffer.from('empty').equals(Buffer.concat(buffers)), 'response body indicates request body was empty')
+			t.end()
+		})
+
+		res.on('data', function (data) {
+			buffers.push(data)
+		})
+	})
+
+	req.write(reference)
+	req.end()
+})
diff --git a/test/server/index.js b/test/server/index.js
index 26962c6..5a042b8 100644
--- a/test/server/index.js
+++ b/test/server/index.js
@@ -71,6 +71,24 @@ app.post('/echo', function (req, res) {
 	req.pipe(res)
 })
 
+app.use('/verifyEmpty', function (req, res) {
+	var empty = true
+	req.on('data', function (buf) {
+		if (buf.length > 0) {
+			empty = false
+		}
+	})
+	req.on('end', function () {
+		res.setHeader('Content-Type', 'text/plain')
+
+		if (empty) {
+			res.end('empty')
+		} else {
+			res.end('not empty')
+		}
+	})
+})
+
 app.use(function (req, res, next) {
 	var parsed = url.parse(req.url, true)
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stream-http.git



More information about the Pkg-javascript-commits mailing list