From de5e3f6a6f5eece5a6927ef17c8bf836c4d0779d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 17 Feb 2012 23:45:50 +0100 Subject: [PATCH] http: support PURGE request method --- src/node_http_parser.cc | 3 + ...-patch.js => test-http-request-methods.js} | 70 ++++++++++--------- 2 files changed, 40 insertions(+), 33 deletions(-) rename test/simple/{test-http-patch.js => test-http-request-methods.js} (55%) diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 8d9000d9d70..1f59c0b070d 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -60,6 +60,7 @@ static Persistent delete_sym; static Persistent get_sym; static Persistent head_sym; static Persistent post_sym; +static Persistent purge_sym; static Persistent put_sym; static Persistent connect_sym; static Persistent options_sym; @@ -126,6 +127,7 @@ method_to_str(unsigned short m) { case HTTP_GET: return get_sym; case HTTP_HEAD: return head_sym; case HTTP_POST: return post_sym; + case HTTP_PURGE: return purge_sym; case HTTP_PUT: return put_sym; case HTTP_CONNECT: return connect_sym; case HTTP_OPTIONS: return options_sym; @@ -613,6 +615,7 @@ void InitHttpParser(Handle target) { get_sym = NODE_PSYMBOL("GET"); head_sym = NODE_PSYMBOL("HEAD"); post_sym = NODE_PSYMBOL("POST"); + purge_sym = NODE_PSYMBOL("PURGE"); put_sym = NODE_PSYMBOL("PUT"); connect_sym = NODE_PSYMBOL("CONNECT"); options_sym = NODE_PSYMBOL("OPTIONS"); diff --git a/test/simple/test-http-patch.js b/test/simple/test-http-request-methods.js similarity index 55% rename from test/simple/test-http-patch.js rename to test/simple/test-http-request-methods.js index 142a0934d8e..f0be3a046e5 100644 --- a/test/simple/test-http-patch.js +++ b/test/simple/test-http-request-methods.js @@ -24,45 +24,49 @@ var assert = require('assert'); var net = require('net'); var http = require('http'); -// Test that the PATCH verb gets passed through correctly +// Test that the PATCH and PURGE verbs get passed through correctly -var server_response = ''; -var received_method = null; +['PATCH', 'PURGE'].forEach(function(method, index) { + var port = common.PORT + index; -var server = http.createServer(function(req, res) { - received_method = req.method; - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('hello '); - res.write('world\n'); - res.end(); -}); -server.listen(common.PORT); + var server_response = ''; + var received_method = null; -server.on('listening', function() { - var c = net.createConnection(common.PORT); + var server = http.createServer(function(req, res) { + received_method = req.method; + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.write('hello '); + res.write('world\n'); + res.end(); + }); + server.listen(port); - c.setEncoding('utf8'); + server.on('listening', function() { + var c = net.createConnection(port); - c.on('connect', function() { - c.write('PATCH / HTTP/1.0\r\n\r\n'); + c.setEncoding('utf8'); + + c.on('connect', function() { + c.write(method + ' / HTTP/1.0\r\n\r\n'); + }); + + c.on('data', function(chunk) { + console.log(chunk); + server_response += chunk; + }); + + c.on('end', function() { + c.end(); + }); + + c.on('close', function() { + server.close(); + }); }); - c.on('data', function(chunk) { - console.log(chunk); - server_response += chunk; - }); - - c.on('end', function() { - c.end(); - }); - - c.on('close', function() { - server.close(); + process.on('exit', function() { + var m = server_response.split('\r\n\r\n'); + assert.equal(m[1], 'hello world\n'); + assert.equal(received_method, method); }); }); - -process.on('exit', function() { - var m = server_response.split('\r\n\r\n'); - assert.equal(m[1], 'hello world\n'); - assert.equal(received_method, 'PATCH'); -});