This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

http: Added support for HTTP PATCH verb

Fixes #1907.
  • Loading branch information...
almost authored and koichik committed Oct 18, 2011
1 parent 6a72e52 commit b0f78afe58d54c6a062c7ce1616c58d424796069
Showing with 71 additions and 0 deletions.
  1. +3 −0 src/node_http_parser.cc
  2. +68 −0 test/simple/test-http-patch.js
View
@@ -67,6 +67,7 @@ static Persistent<String> put_sym;
static Persistent<String> connect_sym;
static Persistent<String> options_sym;
static Persistent<String> trace_sym;
static Persistent<String> patch_sym;
static Persistent<String> copy_sym;
static Persistent<String> lock_sym;
static Persistent<String> mkcol_sym;
@@ -153,6 +154,7 @@ method_to_str(unsigned short m) {
case HTTP_CONNECT: return connect_sym;
case HTTP_OPTIONS: return options_sym;
case HTTP_TRACE: return trace_sym;
case HTTP_PATCH: return patch_sym;
case HTTP_COPY: return copy_sym;
case HTTP_LOCK: return lock_sym;
case HTTP_MKCOL: return mkcol_sym;
@@ -400,6 +402,7 @@ void InitHttpParser(Handle<Object> target) {
connect_sym = NODE_PSYMBOL("CONNECT");
options_sym = NODE_PSYMBOL("OPTIONS");
trace_sym = NODE_PSYMBOL("TRACE");
patch_sym = NODE_PSYMBOL("PATCH");
copy_sym = NODE_PSYMBOL("COPY");
lock_sym = NODE_PSYMBOL("LOCK");
mkcol_sym = NODE_PSYMBOL("MKCOL");
@@ -0,0 +1,68 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var common = require('../common');
var assert = require('assert');
var net = require('net');
var http = require('http');
// Test that the PATCH verb gets passed through correctly
var server_response = '';
var received_method = null;
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);
server.on('listening', function() {
var c = net.createConnection(common.PORT);
c.setEncoding('utf8');
c.on('connect', function() {
c.write('PATCH / 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();
});
});
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');
});

0 comments on commit b0f78af

Please sign in to comment.