11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst http = require('http'); 61cb0ef41Sopenharmony_ciconst net = require('net'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustCall(function(req, res) { 91cb0ef41Sopenharmony_ci res.end(); 101cb0ef41Sopenharmony_ci})); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciserver.on('clientError', common.mustCall(function(err, socket) { 131cb0ef41Sopenharmony_ci assert.strictEqual(err instanceof Error, true); 141cb0ef41Sopenharmony_ci assert.strictEqual(err.code, 'HPE_INVALID_METHOD'); 151cb0ef41Sopenharmony_ci assert.strictEqual(err.bytesParsed, 1); 161cb0ef41Sopenharmony_ci assert.strictEqual(err.message, 'Parse Error: Invalid method encountered'); 171cb0ef41Sopenharmony_ci assert.strictEqual(err.rawPacket.toString(), 'Oopsie-doopsie\r\n'); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci server.close(); 221cb0ef41Sopenharmony_ci})); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciserver.listen(0, function() { 251cb0ef41Sopenharmony_ci function next() { 261cb0ef41Sopenharmony_ci // Invalid request 271cb0ef41Sopenharmony_ci const client = net.connect(server.address().port); 281cb0ef41Sopenharmony_ci client.end('Oopsie-doopsie\r\n'); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci let chunks = ''; 311cb0ef41Sopenharmony_ci client.on('data', function(chunk) { 321cb0ef41Sopenharmony_ci chunks += chunk; 331cb0ef41Sopenharmony_ci }); 341cb0ef41Sopenharmony_ci client.once('end', function() { 351cb0ef41Sopenharmony_ci assert.strictEqual(chunks, 'HTTP/1.1 400 Bad Request\r\n\r\n'); 361cb0ef41Sopenharmony_ci }); 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci // Normal request 401cb0ef41Sopenharmony_ci http.get({ port: this.address().port, path: '/' }, function(res) { 411cb0ef41Sopenharmony_ci assert.strictEqual(res.statusCode, 200); 421cb0ef41Sopenharmony_ci res.resume(); 431cb0ef41Sopenharmony_ci res.once('end', next); 441cb0ef41Sopenharmony_ci }); 451cb0ef41Sopenharmony_ci}); 46