Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support for HTTP PATCH Verb! #1907

Closed
wants to merge 2 commits into from

4 participants

@almost

It's an actual RFC now, can we have Node.JS support for it please!

http://tools.ietf.org/html/rfc5789

@koichik
Owner

Can you sign the CLA?

@miksago

LGTM, can we have a test for it?

@almost

I've signed the CLA (electronic version, my full name is "Thomas Parslow"). I've added a test as well, just checking that the method name gets passed through, hope that's ok!

@koichik koichik closed this in b0f78af
@koichik
Owner

@almost - I squashed into a single commit, thanks!

@felixge
Owner

@koichik How come this patch be done in node and not in the parser repo first?

https://github.com/joyent/http-parser

@koichik
Owner

@felixge - It is src/node_http_parser.cc, not deps/http-parser/http-parser.c :)
http-parser has already supported PATCH method (joyent/http-parser@eee6012).

@felixge
Owner

@koichik ohhh, my bad. I should have read the file name, duh : ). LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 18, 2011
  1. @almost
Commits on Oct 19, 2011
  1. @almost
This page is out of date. Refresh to see the latest.
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
3  src/node_http_parser.cc
@@ -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");
View
68 test/simple/test-http-patch.js
@@ -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');
+});
Something went wrong with that request. Please try again.