123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- module.exports =
- /******/ (function(modules) { // webpackBootstrap
- /******/ // The module cache
- /******/ var installedModules = {};
- /******/ // The require function
- /******/ function __webpack_require__(moduleId) {
- /******/ // Check if module is in cache
- /******/ if(installedModules[moduleId])
- /******/ return installedModules[moduleId].exports;
- /******/ // Create a new module (and put it into the cache)
- /******/ var module = installedModules[moduleId] = {
- /******/ exports: {},
- /******/ id: moduleId,
- /******/ loaded: false
- /******/ };
- /******/ // Execute the module function
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
- /******/ // Flag the module as loaded
- /******/ module.loaded = true;
- /******/ // Return the exports of the module
- /******/ return module.exports;
- /******/ }
- /******/ // expose the modules object (__webpack_modules__)
- /******/ __webpack_require__.m = modules;
- /******/ // expose the module cache
- /******/ __webpack_require__.c = installedModules;
- /******/ // __webpack_public_path__
- /******/ __webpack_require__.p = "";
- /******/ // Load entry module and return exports
- /******/ return __webpack_require__(0);
- /******/ })
- /************************************************************************/
- /******/ ([
- /* 0 */
- /***/ function(module, exports, __webpack_require__) {
- module.exports = __webpack_require__(1);
- /***/ },
- /* 1 */
- /***/ function(module, exports, __webpack_require__) {
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _xmlParser = __webpack_require__(2);
- var _xmlParser2 = _interopRequireDefault(_xmlParser);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- var onerror = function onerror() {};
- exports.default = function () {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { onerror: onerror };
- return function* (next) {
- /**
- * only parse and set this.request.body when
- * 1. type is xml (text/xml and application/xml)
- * 2. method is post/put/patch
- * 3. this.request.body is undefined
- */
- if (this.request.body === undefined && this.is('text/xml', 'xml') && /^(POST|PUT|PATCH)$/i.test(this.method)) {
- if (!options.encoding && this.request.charset) {
- options.encoding = this.request.charset;
- }
- try {
- this.request.body = yield (0, _xmlParser2.default)(this.req, options);
- } catch (err) {
- // if want to throw error, set onerror to null
- if (options.onerror) {
- options.onerror(err, this);
- } else {
- throw err;
- }
- }
- }
- yield next;
- };
- };
- /***/ },
- /* 2 */
- /***/ function(module, exports, __webpack_require__) {
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _xml2js = __webpack_require__(3);
- var _rawBody = __webpack_require__(4);
- var _rawBody2 = _interopRequireDefault(_rawBody);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- var convertXml2Json = function convertXml2Json() /* str, options */{
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- return new Promise(function (resolve, reject) {
- var cb = function cb(err, result) {
- err ? reject(err) : resolve(result);
- };
- _xml2js.parseString.apply(undefined, args.concat([cb]));
- });
- };
- var parse = function parse(request) {
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
- _ref$limit = _ref.limit,
- limit = _ref$limit === undefined ? '1mb' : _ref$limit,
- _ref$encoding = _ref.encoding,
- encoding = _ref$encoding === undefined ? 'utf8' : _ref$encoding,
- length = _ref.length,
- xmlOptions = _ref.xmlOptions;
- var len = request.headers['content-length'];
- // set options
- if (len) {
- length = len = ~~len;
- }
- return (0, _rawBody2.default)(request, { limit: limit, encoding: encoding, length: length }).then(function (str) {
- return convertXml2Json(str, xmlOptions || {}).catch(function (err) {
- err = typeof err === 'string' ? new Error(err) : err;
- err.status = 400;
- err.body = str;
- throw err;
- });
- }).catch(function (err) {
- throw err;
- });
- };
- exports.default = parse;
- /***/ },
- /* 3 */
- /***/ function(module, exports) {
- module.exports = require("xml2js");
- /***/ },
- /* 4 */
- /***/ function(module, exports) {
- module.exports = require("raw-body");
- /***/ }
- /******/ ]);
|