summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-client-error-rawbytes.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/parallel/test-http-client-error-rawbytes.js')
-rw-r--r--test/parallel/test-http-client-error-rawbytes.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/parallel/test-http-client-error-rawbytes.js b/test/parallel/test-http-client-error-rawbytes.js
new file mode 100644
index 0000000000..909fcc796a
--- /dev/null
+++ b/test/parallel/test-http-client-error-rawbytes.js
@@ -0,0 +1,32 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const http = require('http');
+const net = require('net');
+
+const response = Buffer.from('HTTP/1.1 200 OK\r\n' +
+ 'Content-Length: 6\r\n' +
+ 'Transfer-Encoding: Chunked\r\n' +
+ '\r\n' +
+ '6\r\nfoobar' +
+ '0\r\n');
+
+const server = net.createServer(common.mustCall((conn) => {
+ conn.write(response);
+}));
+
+server.listen(0, common.mustCall(() => {
+ const req = http.get(`http://localhost:${server.address().port}/`);
+ req.end();
+ req.on('error', common.mustCall((err) => {
+ const reason = 'Content-Length can\'t be present with chunked encoding';
+ assert.strictEqual(err.message, `Parse Error: ${reason}`);
+ assert(err.bytesParsed < response.length);
+ assert(err.bytesParsed >= response.indexOf('Transfer-Encoding'));
+ assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
+ assert.strictEqual(err.reason, reason);
+ assert.deepStrictEqual(err.rawPacket, response);
+
+ server.close();
+ }));
+}));