Skip to content
This repository
Browse code

http: support PURGE request method

  • Loading branch information...
commit de5e3f6a6f5eece5a6927ef17c8bf836c4d0779d 1 parent f0c5165
Ben Noordhuis bnoordhuis authored
3  src/node_http_parser.cc
@@ -60,6 +60,7 @@ static Persistent<String> delete_sym;
60 60 static Persistent<String> get_sym;
61 61 static Persistent<String> head_sym;
62 62 static Persistent<String> post_sym;
  63 +static Persistent<String> purge_sym;
63 64 static Persistent<String> put_sym;
64 65 static Persistent<String> connect_sym;
65 66 static Persistent<String> options_sym;
@@ -126,6 +127,7 @@ method_to_str(unsigned short m) {
126 127 case HTTP_GET: return get_sym;
127 128 case HTTP_HEAD: return head_sym;
128 129 case HTTP_POST: return post_sym;
  130 + case HTTP_PURGE: return purge_sym;
129 131 case HTTP_PUT: return put_sym;
130 132 case HTTP_CONNECT: return connect_sym;
131 133 case HTTP_OPTIONS: return options_sym;
@@ -613,6 +615,7 @@ void InitHttpParser(Handle<Object> target) {
613 615 get_sym = NODE_PSYMBOL("GET");
614 616 head_sym = NODE_PSYMBOL("HEAD");
615 617 post_sym = NODE_PSYMBOL("POST");
  618 + purge_sym = NODE_PSYMBOL("PURGE");
616 619 put_sym = NODE_PSYMBOL("PUT");
617 620 connect_sym = NODE_PSYMBOL("CONNECT");
618 621 options_sym = NODE_PSYMBOL("OPTIONS");
66 test/simple/test-http-patch.js → test/simple/test-http-request-methods.js
@@ -24,45 +24,49 @@ var assert = require('assert');
24 24 var net = require('net');
25 25 var http = require('http');
26 26
27   -// Test that the PATCH verb gets passed through correctly
  27 +// Test that the PATCH and PURGE verbs get passed through correctly
28 28
29   -var server_response = '';
30   -var received_method = null;
  29 +['PATCH', 'PURGE'].forEach(function(method, index) {
  30 + var port = common.PORT + index;
31 31
32   -var server = http.createServer(function(req, res) {
33   - received_method = req.method;
34   - res.writeHead(200, {'Content-Type': 'text/plain'});
35   - res.write('hello ');
36   - res.write('world\n');
37   - res.end();
38   -});
39   -server.listen(common.PORT);
  32 + var server_response = '';
  33 + var received_method = null;
40 34
41   -server.on('listening', function() {
42   - var c = net.createConnection(common.PORT);
  35 + var server = http.createServer(function(req, res) {
  36 + received_method = req.method;
  37 + res.writeHead(200, {'Content-Type': 'text/plain'});
  38 + res.write('hello ');
  39 + res.write('world\n');
  40 + res.end();
  41 + });
  42 + server.listen(port);
43 43
44   - c.setEncoding('utf8');
  44 + server.on('listening', function() {
  45 + var c = net.createConnection(port);
45 46
46   - c.on('connect', function() {
47   - c.write('PATCH / HTTP/1.0\r\n\r\n');
48   - });
  47 + c.setEncoding('utf8');
49 48
50   - c.on('data', function(chunk) {
51   - console.log(chunk);
52   - server_response += chunk;
53   - });
  49 + c.on('connect', function() {
  50 + c.write(method + ' / HTTP/1.0\r\n\r\n');
  51 + });
54 52
55   - c.on('end', function() {
56   - c.end();
57   - });
  53 + c.on('data', function(chunk) {
  54 + console.log(chunk);
  55 + server_response += chunk;
  56 + });
  57 +
  58 + c.on('end', function() {
  59 + c.end();
  60 + });
58 61
59   - c.on('close', function() {
60   - server.close();
  62 + c.on('close', function() {
  63 + server.close();
  64 + });
61 65 });
62   -});
63 66
64   -process.on('exit', function() {
65   - var m = server_response.split('\r\n\r\n');
66   - assert.equal(m[1], 'hello world\n');
67   - assert.equal(received_method, 'PATCH');
  67 + process.on('exit', function() {
  68 + var m = server_response.split('\r\n\r\n');
  69 + assert.equal(m[1], 'hello world\n');
  70 + assert.equal(received_method, method);
  71 + });
68 72 });

0 comments on commit de5e3f6

Please sign in to comment.
Something went wrong with that request. Please try again.