1// Copyright Joyent, Inc. and other Node contributors. 2// 3// Permission is hereby granted, free of charge, to any person obtaining a 4// copy of this software and associated documentation files (the 5// "Software"), to deal in the Software without restriction, including 6// without limitation the rights to use, copy, modify, merge, publish, 7// distribute, sublicense, and/or sell copies of the Software, and to permit 8// persons to whom the Software is furnished to do so, subject to the 9// following conditions: 10// 11// The above copyright notice and this permission notice shall be included 12// in all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20// USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22'use strict'; 23const common = require('../common'); 24const assert = require('assert'); 25const net = require('net'); 26const http = require('http'); 27 28// Test that the DELETE, PATCH and PURGE verbs get passed through correctly 29 30['DELETE', 'PATCH', 'PURGE'].forEach(function(method, index) { 31 const server = http.createServer(common.mustCall(function(req, res) { 32 assert.strictEqual(req.method, method); 33 res.writeHead(200, { 'Content-Type': 'text/plain' }); 34 res.write('hello '); 35 res.write('world\n'); 36 res.end(); 37 })); 38 server.listen(0); 39 40 server.on('listening', common.mustCall(function() { 41 const c = net.createConnection(this.address().port); 42 let server_response = ''; 43 44 c.setEncoding('utf8'); 45 46 c.on('connect', function() { 47 c.write(`${method} / HTTP/1.0\r\n\r\n`); 48 }); 49 50 c.on('data', function(chunk) { 51 console.log(chunk); 52 server_response += chunk; 53 }); 54 55 c.on('end', common.mustCall(function() { 56 const m = server_response.split('\r\n\r\n'); 57 assert.strictEqual(m[1], 'hello world\n'); 58 c.end(); 59 })); 60 61 c.on('close', function() { 62 server.close(); 63 }); 64 })); 65}); 66