Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payload bugfix for PATCH method #817

Merged
merged 4 commits into from May 6, 2013
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not changed (and should not).

- `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.
Expand Down Expand Up @@ -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).
<p></p>
- `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).
<p></p>
- `vhost` - an optional domain string or an array of domain strings for limiting the route to only requests with a matching host header field.
Expand Down Expand Up @@ -415,7 +415,7 @@ The following options are available when adding a route:
- `log` - log the error but send the response.
<p></p>
- `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.
Expand Down
2 changes: 1 addition & 1 deletion lib/payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
2 changes: 1 addition & 1 deletion test/unit/payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down