-
Notifications
You must be signed in to change notification settings - Fork 982
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support passing most qs options to restify.queryParser (#1209)
Fixes #925
- Loading branch information
Showing
6 changed files
with
415 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -929,14 +929,41 @@ interpreted in seconds, to allow for clock skew. | |
|
||
### QueryParser | ||
|
||
server.use(restify.queryParser()); | ||
server.use(restify.queryParser([OPTIONS])); | ||
|
||
Parses the HTTP query string (e.g., `/foo?id=bar&name=mark`) to an object on | ||
`req.query`, e.g. `{id: 'bar', name: 'mark'}`. | ||
|
||
By default, query params are merged into `req.params` (which may include | ||
parameters from `restify.bodyParser`). This can be disabled by the `mapParams` | ||
option: | ||
|
||
server.use(restify.queryParser({mapParams: false})); | ||
|
||
QueryParser options are as follows. All but `mapParams` are directly passed to | ||
the underlying ["qs" module](https://github.com/ljharb/qs#readme). | ||
|
||
|| **Option** || **Type** || **Default** || **Description** || | ||
|| mapParams || bool || true || Whether to merge req.query into req.params. || | ||
|| allowDots || bool || true \* || Transform `?foo.bar=baz` to a nested object: `{foo: {bar: 'baz'}}`. || | ||
|| arrayLimit || num || 20 || Only transform `?a[$index]=b` to an array if `$index` is less than `arrayLimit`. || | ||
|| depth || num || 5 || The depth limit for parsing nested objects, e.g. `?a[b][c][d][e][f][g][h][i]=j`. || | ||
|| parameterLimit || num || 1000 || Maximum number of query params parsed. Additional params are silently dropped. || | ||
|| parseArrays || bool || true || Whether to parse `?a[]=b&a[1]=c` to an array, e.g. `{a: ['b', 'c']}`. || | ||
|| plainObjects || bool || true \* || Whether `req.query` is a "plain" object -- does not inherit from `Object`. This can be used to allow query params whose names collide with Object methods, e.g. `?hasOwnProperty=blah`. || | ||
|| strictNullHandling || bool || false || If true, `?a&b=` results in `{a: null, b: ''}`. Otherwise, `{a: '', b: ''}`. || | ||
|
||
\*: The `allowDots` and `plainObjects` options are `true` by default in restify | ||
4.x because of an accident. Restify 4.0 updated from qs@2 to qs@3, which changed | ||
default behavior to this. Subsequent qs major versions reverted that behaviour. | ||
The restify 4.x stream will maintain this default, but all other major versions | ||
of restify (those before v4) and the `queryParser` plugin in [email protected] | ||
and later (restify 5.x no longer bundles the plugins) default to | ||
`allowDots=false` and `plainObjects=false`. The recommended usage (for new | ||
code or to maintain compat across restify major versions is): | ||
|
||
Parses the HTTP query string (i.e., `/foo?id=bar&name=mark`). If you use this, | ||
the parsed content will always be available in `req.query`, additionally params | ||
are merged into `req.params`. You can disable by passing in `mapParams: false` | ||
in the options object: | ||
server.use(restify.queryParser({allowDots: false, plainObjects: false})); | ||
|
||
server.use(restify.queryParser({ mapParams: false })); | ||
|
||
### JSONP | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.