form.js 775 B

123456789101112131415161718192021222324252627282930313233
  1. var querystringParse = require("querystring").parse
  2. var body = require("./index.js")
  3. var parseArguments = require("./parse-arguments.js")
  4. module.exports = formBody
  5. function formBody(req, res, opts, callback) {
  6. var args = parseArguments(req, res, opts, callback)
  7. req = args.req
  8. res = args.res
  9. opts = args.opts
  10. callback = args.callback
  11. if (!callback) {
  12. return formBody.bind(null, req, res, opts)
  13. }
  14. var parse = opts.querystring ?
  15. opts.querystring.parse : defaultQueryStringParse
  16. body(req, res, opts, function (err, body) {
  17. if (err) {
  18. return callback(err)
  19. }
  20. parse(body, callback)
  21. })
  22. }
  23. function defaultQueryStringParse(str, callback) {
  24. callback(null, querystringParse(str))
  25. }