From 232a7e90d2c6c9a65f2a2ca43b0b1e30d255d96d Mon Sep 17 00:00:00 2001 From: Christian Tellnes Date: Wed, 1 Jan 2014 18:53:07 +0100 Subject: [PATCH] add support for more methods --- lib/http-console.js | 9 ++++++--- package.json | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/http-console.js b/lib/http-console.js index 73cfb78..7017918 100644 --- a/lib/http-console.js +++ b/lib/http-console.js @@ -5,7 +5,8 @@ var http = require('http'), events = require('events'), queryString = require('querystring'), readline = require('readline'), - sys = require('util'); + sys = require('util'), + methods = require('methods'); require('./ext'); @@ -17,6 +18,8 @@ try { var consoles = []; +var reMethods = new RegExp('^(' + methods.join('|') + ')', 'i') + this.Console = function (host, port, options) { this.host = host; this.port = parseInt(port); @@ -181,7 +184,7 @@ this.Console.prototype = new(function () { } else { delete(this.headers[match[1]]); } - } else if (/^(GET|POST|PUT|HEAD|DELETE|OPTIONS)/i.test(command)) { + } else if (reMethods.test(command)) { command = command.split(/\s+/); method = command.shift().toUpperCase(); path = this.path.slice(0); @@ -190,7 +193,7 @@ this.Console.prototype = new(function () { path = ('/' + path.join('/')).replace(/\/+/g, '/'); - if (method === 'PUT' || method === 'POST') { + if (method !== 'GET' && method !== 'HEAD') { this.pending = { method: method, path: path }; this.dataPrompt(); } else { diff --git a/package.json b/package.json index 79418df..5d9cf88 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "keywords" : ["http", "console", "repl"], "author" : "Alexis Sellier ", "contributors" : [], - "dependencies" : { "eyes": ">=0.1.4" }, + "dependencies" : { "eyes": ">=0.1.4", "methods": "~0.1.0" }, "version" : "0.6.2", "main" : "./lib/http-console", "directories" : { "lib": "./lib", "test": "./test" },