Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
http: support PURGE request method
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Feb 20, 2012
1 parent f0c5165 commit de5e3f6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
3 changes: 3 additions & 0 deletions src/node_http_parser.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Expand Up @@ -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 de5e3f6

Please sign in to comment.