http: support PURGE request method
This commit is contained in:
parent
f0c5165f81
commit
de5e3f6a6f
@ -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('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');
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user