From 8a14ddfceab577939b8cf10f794cd74326bb51e7 Mon Sep 17 00:00:00 2001 From: Geoffroy Date: Sun, 5 May 2013 01:19:55 +0200 Subject: [PATCH 1/4] Payload : fix to parse request data on "PATCH" method --- lib/payload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/payload.js b/lib/payload.js index 803025ca8..34c507ca8 100755 --- a/lib/payload.js +++ b/lib/payload.js @@ -27,7 +27,7 @@ exports.read = function (request, next) { // Levels are: 'stream', 'raw', 'parse' - var level = request.route.payload || (request.route.validate.payload || request.method === 'post' || request.method === 'put' ? 'parse' : 'stream'); + var level = request.route.payload || (request.route.validate.payload || request.method === 'post' || request.method === 'put'|| request.method === 'patch' ? 'parse' : 'stream'); if (level === 'stream') { return next(); } From c35c28570cd879038956a3197c33303ecff4b212 Mon Sep 17 00:00:00 2001 From: Geoffroy Date: Sun, 5 May 2013 18:09:25 +0200 Subject: [PATCH 2/4] Reference doc : "PATCH" method added --- docs/Reference.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Reference.md b/docs/Reference.md index cdce7e0b7..8ffdd83d4 100755 --- a/docs/Reference.md +++ b/docs/Reference.md @@ -166,7 +166,7 @@ When creating a server instance, the following options configure the server's be will take before the browser checks for changes in policy. Defaults to `86400` (one day). - `headers` - a strings array of allowed headers ('Access-Control-Allow-Headers'). Defaults to `['Authorization', 'Content-Type', 'If-None-Match']`. - `additionalHeaders` - a strings array of additional headers to `headers`. Use this to keep the default headers in place. - - `methods` - a strings array of allowed HTTP methods ('Access-Control-Allow-Methods'). Defaults to `['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS']`. + - `methods` - a strings array of allowed HTTP methods ('Access-Control-Allow-Methods'). Defaults to `['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']`. - `additionalMethods` - a strings array of additional methods to `methods`. Use this to keep the default methods in place. - `exposedHeaders` - a strings array of exposed headers ('Access-Control-Expose-Headers'). Defaults to `['WWW-Authenticate', 'Server-Authorization']`. - `additionalExposedHeaders` - a strings array of additional headers to `exposedHeaders`. Use this to keep the default headers in place. @@ -316,7 +316,7 @@ The following options are available when adding a route: paths based on the server [`router`](#server.config.router) configuration option. The path can include named parameters enclosed in `{}` which will be matched against literal values in the request as described in [Path parameters](#path-parameters).

-- `method` - (required) the HTTP method. Typically one of 'GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'. Any HTTP method is allowed, except for 'HEAD'. +- `method` - (required) the HTTP method. Typically one of 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'. Any HTTP method is allowed, except for 'HEAD'. Use `*` to match against any HTTP method (only when an exact match was not found).

- `vhost` - an optional domain string or an array of domain strings for limiting the route to only requests with a matching host header field. @@ -415,7 +415,7 @@ The following options are available when adding a route: - `log` - log the error but send the response.

- `payload` - determines how the request payload is processed. Defaults to `'parse'` if `validate.payload` is set or when `method` is - `'POST'` or `'PUT'`, otherwise `'stream'`. Payload processing is configured using the server [`payload`](#server.config.payload) configuration. + `'POST'`, `'PUT'` or `'PATCH'`, otherwise `'stream'`. Payload processing is configured using the server [`payload`](#server.config.payload) configuration. Options are: - `'stream'` - the incoming request stream is left untouched, leaving it up to the handler to process the request via `request.raw.req`. - `'raw'` - the payload is read and stored in `request.rawPayload` as a `Buffer` and is not parsed. From 72f1b57e293a87f1cdfd196a0d28aeaa2b8e1e51 Mon Sep 17 00:00:00 2001 From: Geoffroy Date: Sun, 5 May 2013 18:12:09 +0200 Subject: [PATCH 3/4] Tests: "PATCH" method mentioned --- test/integration/payload.js | 2 +- test/unit/payload.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/payload.js b/test/integration/payload.js index b0459e87e..582ce9dfc 100755 --- a/test/integration/payload.js +++ b/test/integration/payload.js @@ -335,7 +335,7 @@ describe('Payload', function () { this.push(null); }; - it('sets parse mode when route methos is * and request is POST or PUT', function (done) { + it('sets parse mode when route methos is * and request is POST, PATCH or PUT', function (done) { server.inject({ url: '/any', method: 'POST', headers: { 'Content-Type': 'application/json' }, payload: '{ "key": "09876" }' }, function (res) { diff --git a/test/unit/payload.js b/test/unit/payload.js index 94ae49275..6e3b3915f 100755 --- a/test/unit/payload.js +++ b/test/unit/payload.js @@ -56,7 +56,7 @@ describe('Payload', function () { }); }); - it('passes null to the callback when the method is not put or post', function (done) { + it('passes null to the callback when the method is not put, patch or post', function (done) { var request = { _timestamp: Date.now(), method: 'delete', From 236629e330e6e8723a1e81eefddd0e881d37a891 Mon Sep 17 00:00:00 2001 From: Geoffroy Date: Sun, 5 May 2013 18:46:02 +0200 Subject: [PATCH 4/4] Reference doc: "PATCH" method removed from cors default methods (commit fail) --- docs/Reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Reference.md b/docs/Reference.md index 8ffdd83d4..7614ed227 100755 --- a/docs/Reference.md +++ b/docs/Reference.md @@ -166,7 +166,7 @@ When creating a server instance, the following options configure the server's be will take before the browser checks for changes in policy. Defaults to `86400` (one day). - `headers` - a strings array of allowed headers ('Access-Control-Allow-Headers'). Defaults to `['Authorization', 'Content-Type', 'If-None-Match']`. - `additionalHeaders` - a strings array of additional headers to `headers`. Use this to keep the default headers in place. - - `methods` - a strings array of allowed HTTP methods ('Access-Control-Allow-Methods'). Defaults to `['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']`. + - `methods` - a strings array of allowed HTTP methods ('Access-Control-Allow-Methods'). Defaults to `['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS']`. - `additionalMethods` - a strings array of additional methods to `methods`. Use this to keep the default methods in place. - `exposedHeaders` - a strings array of exposed headers ('Access-Control-Expose-Headers'). Defaults to `['WWW-Authenticate', 'Server-Authorization']`. - `additionalExposedHeaders` - a strings array of additional headers to `exposedHeaders`. Use this to keep the default headers in place.