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

Support for HTTP PATCH Verb! #1907

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
68 changes: 68 additions & 0 deletions test/simple/test-http-patch.js
Original file line number Diff line number Diff line change
@@ -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');
});