method-override
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -0,1 +1,10 @@ | ||
2.1.0 / 2014-07-08 | ||
================== | ||
* add simple debug output | ||
* deps: methods@1.1.0 | ||
- add `CONNECT` | ||
* deps: parseurl@~1.1.3 | ||
- faster parsing of href-only URLs | ||
2.0.2 / 2014-06-05 | ||
@@ -2,0 +11,0 @@ ================== |
@@ -14,2 +14,3 @@ /*! | ||
var debug = require('debug')('method-override') | ||
var methods = require('methods'); | ||
@@ -61,3 +62,3 @@ var parseurl = require('parseurl'); | ||
// validate request is on allowed method | ||
// validate request is an allowed method | ||
if (methods && methods.indexOf(req.originalMethod) === -1) { | ||
@@ -75,2 +76,3 @@ return next() | ||
req.method = method.toUpperCase() | ||
debug('override %s as %s', req.originalMethod, req.method) | ||
} | ||
@@ -77,0 +79,0 @@ |
{ | ||
"name": "method-override", | ||
"description": "Override HTTP verbs", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)", | ||
@@ -12,8 +12,9 @@ "contributors": [ | ||
"dependencies": { | ||
"methods": "1.0.1", | ||
"parseurl": "1.0.1", | ||
"debug": "1.0.2", | ||
"methods": "1.1.0", | ||
"parseurl": "~1.1.3", | ||
"vary": "0.1.0" | ||
}, | ||
"devDependencies": { | ||
"istanbul": "0.2.10", | ||
"istanbul": "0.3.0", | ||
"mocha": "~1.20.0", | ||
@@ -20,0 +21,0 @@ "supertest": "~0.13.0" |
@@ -60,3 +60,5 @@ # method-override | ||
the call, send a `POST` request to a URL with the overridden method | ||
as the value of that header. | ||
as the value of that header. This method of using a header would | ||
typically be used in conjunction with `XMLHttpRequest` on implementations | ||
that do not support the method you are trying to use. | ||
@@ -71,12 +73,15 @@ ```js | ||
Example call with header override using `curl`: | ||
Example call with header override using `XMLHttpRequest`: | ||
```js | ||
var xhr = new XMLHttpRequest() | ||
xhr.onload = onload | ||
xhr.open('post', '/resource', true) | ||
xhr.setRequestHeader('X-HTTP-Method-Override', 'DELETE') | ||
xhr.send() | ||
function onload() { | ||
alert('got response: ' + this.responseText) | ||
} | ||
``` | ||
curl -XPOST -H'X-HTTP-Method-Override: DELETE' --verbose http://localhost:3000/resource | ||
> POST /resource HTTP/1.1 | ||
> Host: localhost:3000 | ||
> X-HTTP-Method-Override: DELETE | ||
> | ||
Cannot DELETE /resource | ||
``` | ||
@@ -88,3 +93,6 @@ ### override using a query value | ||
then make the call, send a `POST` request to a URL with the overridden | ||
method as the value of that query string key. | ||
method as the value of that query string key. This method of using a | ||
query value would typically be used in conjunction with plain HTML | ||
`<form>` elements when trying to support legacy browsers but still use | ||
newer methods. | ||
@@ -99,11 +107,9 @@ ```js | ||
Example call with query override using `curl`: | ||
Example call with query override using HTML `<form>`: | ||
```html | ||
<form method="POST" action="/resource?_method=DELETE"> | ||
<button type="submit">Delete resource</button> | ||
</form> | ||
``` | ||
curl -XPOST --verbose http://localhost:3000/resource?_method=DELETE | ||
> POST /resource?_method=DELETE HTTP/1.1 | ||
> Host: localhost:3000 | ||
> | ||
Cannot DELETE /resource?_method=DELETE | ||
``` | ||
@@ -125,3 +131,3 @@ ### multiple format support | ||
You can implement any kind of custom logic with a function for the `getter`. The following | ||
implements the logic for looking in `req.body` that was in `method-override` 1: | ||
implements the logic for looking in `req.body` that was in `method-override@1`: | ||
@@ -133,2 +139,5 @@ ```js | ||
// NOTE: when using req.body, you must fully parse the request body | ||
// before you call methodOverride() in your middleware stack, | ||
// otherwise req.body will not be populated. | ||
app.use(bodyParser.urlencoded()) | ||
@@ -145,2 +154,12 @@ app.use(methodOverride(function(req, res){ | ||
Example call with query override using HTML `<form>`: | ||
```html | ||
<!-- enctype must be set to the type you will parse before methodOverride() --> | ||
<form method="POST" action="/resource" enctype="application/x-www-form-urlencoded"> | ||
<input type="hidden" name="_method" value="DELETE"> | ||
<button type="submit">Delete resource</button> | ||
</form> | ||
``` | ||
## License | ||
@@ -147,0 +166,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11743
107
181
4
+ Addeddebug@1.0.2
+ Addeddebug@1.0.2(transitive)
+ Addedmethods@1.1.0(transitive)
+ Addedms@0.6.2(transitive)
+ Addedparseurl@1.1.3(transitive)
- Removedmethods@1.0.1(transitive)
- Removedparseurl@1.0.1(transitive)
Updatedmethods@1.1.0
Updatedparseurl@~1.1.3