Permalink
Browse files

http: support PURGE request method

  • Loading branch information...
1 parent f76d3c7 commit 998698909dde4033140d4b43a0e1ac4c1c4b902b @bnoordhuis committed Feb 17, 2012
Showing with 38 additions and 31 deletions.
  1. +3 −0 src/node_http_parser.cc
  2. +35 −31 test/simple/{test-http-patch.js → test-http-request-methods.js}
View
@@ -60,6 +60,7 @@ static Persistent<String> delete_sym;
static Persistent<String> get_sym;
static Persistent<String> head_sym;
static Persistent<String> post_sym;
+static Persistent<String> purge_sym;
static Persistent<String> put_sym;
static Persistent<String> connect_sym;
static Persistent<String> 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<Object> 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");
@@ -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('data', function(chunk) {
- console.log(chunk);
- server_response += chunk;
- });
+ c.on('connect', function() {
+ c.write(method + ' / HTTP/1.0\r\n\r\n');
+ });
- c.on('end', function() {
- c.end();
- });
+ 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('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, 'PATCH');
+ 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);
+ });
});

0 comments on commit 9986989

Please sign in to comment.