Name: js-handler/node_modules/restify/lib/plugins/query.js 
1:
// Copyright 2012 Mark Cavage, Inc.  All rights reserved.
2:
 
3:
var qs = require('qs');
4:
var url = require('url');
5:
 
6:
var assert = require('assert-plus');
7:
 
8:
 
9:
 
10:
/**
11:
 * Returns a plugin that will parse the query string, and merge the results
12:
 * into req.params.
13:
 *
14:
 * @return {Function} restify handler.
15:
 * @throws {TypeError} on bad input
16:
 */
17:
function queryParser(options) {
18:
        if (!options)
19:
                options = {};
20:
        assert.object(options, 'options');
21:
 
22:
 
23:
        function parseQueryString(req, res, next) {
24:
                if (!req.getQuery()) {
25:
                        req.query = {};
26:
                        return (next());
27:
                }
28:
 
29:
                req._query = req.query = qs.parse(req.getQuery());
30:
                if (options.mapParams !== false) {
31:
                        Object.keys(req.query).forEach(function (k) {
32:
                                if (req.params[k] && !options.overrideParams)
33:
                                        return (false);
34:
 
35:
                                req.params[k] = req.query[k];
36:
                                return (true);
37:
                        });
38:
                }
39:
 
40:
                return (next());
41:
        }
42:
 
43:
        return (parseQueryString);
44:
}
45:
 
46:
module.exports = queryParser;