UNPKG

app-lib-mock-server-parse

Version:

body解析-【app-lib-mock-server-parse】

3 lines 11 kB
/*! For license information please see index-min.js.LICENSE.txt */ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("bytes"),require("content-type"),require("debug"),require("depd"),require("destroy"),require("http-errors"),require("iconv-lite"),require("on-finished"),require("qs"),require("querystring"),require("raw-body"),require("type-is"),require("unpipe"),require("zlib"));else if("function"==typeof define&&define.amd)define(["bytes","content-type","debug","depd","destroy","http-errors","iconv-lite","on-finished","qs","querystring","raw-body","type-is","unpipe","zlib"],t);else{var r="object"==typeof exports?t(require("bytes"),require("content-type"),require("debug"),require("depd"),require("destroy"),require("http-errors"),require("iconv-lite"),require("on-finished"),require("qs"),require("querystring"),require("raw-body"),require("type-is"),require("unpipe"),require("zlib")):t(e.bytes,e["content-type"],e.debug,e.depd,e.destroy,e["http-errors"],e["iconv-lite"],e["on-finished"],e.qs,e.querystring,e["raw-body"],e["type-is"],e.unpipe,e.zlib);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,((e,t,r,n,i,o,a,s,u,p,d,c,y,f)=>{return l={814:(e,t,r)=>{"use strict";var n=r(622)("body-parser"),i=Object.create(null);function o(e){return function(){return function(e){var t=i[e];if(void 0!==t)return t;switch(e){case"json":t=r(2);break;case"raw":t=r(842);break;case"text":t=r(492);break;case"urlencoded":t=r(980)}return i[e]=t}(e)}}t=e.exports=n.function((function(e){var r=Object.create(e||null,{type:{configurable:!0,enumerable:!0,value:void 0,writable:!0}}),n=t.urlencoded(r),i=t.json(r);return function(e,t,r){i(e,t,(function(i){if(i)return r(i);n(e,t,r)}))}}),"bodyParser: use individual json/urlencoded middlewares"),Object.defineProperty(t,"json",{configurable:!0,enumerable:!0,get:o("json")}),Object.defineProperty(t,"raw",{configurable:!0,enumerable:!0,get:o("raw")}),Object.defineProperty(t,"text",{configurable:!0,enumerable:!0,get:o("text")}),Object.defineProperty(t,"urlencoded",{configurable:!0,enumerable:!0,get:o("urlencoded")})},992:(e,t,r)=>{"use strict";var n=r(790),i=r(57),o=r(379),a=r(671),s=r(544),u=r(961),p=r(638);e.exports=function(e,t,r,d,c,y){var f=e.__bodyData?.length,l=y,b=e.__bodyData?.stream;e._body=!0;var v=null!==l.encoding?l.encoding:null,m=l.verify;if(!e.__bodyData)try{b=function(e,t,r){var i,o=(e.headers["content-encoding"]||"identity").toLowerCase(),a=e.headers["content-length"];if(t('content-encoding "%s"',o),!1===r&&"identity"!==o)throw n(415,"content encoding unsupported",{encoding:o,type:"encoding.unsupported"});switch(o){case"deflate":i=p.createInflate(),t("inflate body"),e.pipe(i);break;case"gzip":i=p.createGunzip(),t("gunzip body"),e.pipe(i);break;case"identity":(i=e).length=a;break;default:throw n(415,'unsupported content encoding "'+o+'"',{encoding:o,type:"encoding.unsupported"})}return i}(e,c,l.inflate),f=b.length,b.length=void 0,e.__bodyData={length:f}}catch(e){return r(e)}if(l.length=f,l.encoding=m?null:v,null===l.encoding&&null!==v&&!a.encodingExists(v))return r(n(415,'unsupported charset "'+v.toUpperCase()+'"',{charset:v.toLowerCase(),type:"charset.unsupported"}));if(c("read body"),e.__bodyData.readStream){var h=e.__bodyData.body;if(m)try{c("verify body"),m(e,t,h,v)}catch(e){return void r(n(403,e,{body:h,type:e.type||"entity.verify.failed"}))}var g=h;try{c("parse body"),g="string"!=typeof h&&null!==v?a.decode(h,v):h,e.body=d(g)}catch(e){return void r(n(400,e,{body:g,type:e.type||"entity.parse.failed"}))}r()}else o(b,l,(function(o,p){var y;if(e.__bodyData.readStream=!0,e.__bodyData.body=p,o)return y="encoding.unsupported"===o.type?n(415,'unsupported charset "'+v.toUpperCase()+'"',{charset:v.toLowerCase(),type:"charset.unsupported"}):n(400,o),b!==e&&(u(e),i(b,!0)),void function(e,t){s.isFinished(e)?t():(s(e,t),e.resume())}(e,(function(){r(n(400,y))}));if(m)try{c("verify body"),m(e,t,p,v)}catch(e){return void r(n(403,e,{body:p,type:e.type||"entity.verify.failed"}))}var f=p;try{c("parse body"),f="string"!=typeof p&&null!==v?a.decode(p,v):p,e.body=d(f)}catch(e){return void r(n(400,e,{body:f,type:e.type||"entity.parse.failed"}))}r()}))}},2:(e,t,r)=>{"use strict";var n=r(348),i=r(897),o=r(790),a=r(999)("body-parser:json"),s=r(992),u=r(240);e.exports=function(e){var t=e||{},r="number"!=typeof t.limit?n.parse(t.limit||"100kb"):t.limit,c=!1!==t.inflate,y=t.reviver,f=!1!==t.strict,l=t.type||"application/json",b=t.verify||!1;if(!1!==b&&"function"!=typeof b)throw new TypeError("option verify must be function");var v="function"!=typeof l?function(e){return function(t){return Boolean(u(t,e))}}(l):l;function m(e){if(0===e.length)return{};if(f){var t=(r=e,(n=p.exec(r))?n[1]:void 0);if("{"!==t&&"["!==t)throw a("strict violation"),function(e,t){var r=e.indexOf(t),n=-1!==r?e.substring(0,r)+"#":"";try{throw JSON.parse(n),new SyntaxError("strict violation")}catch(e){return d(e,{message:e.message.replace("#",t),stack:e.stack})}}(e,t)}var r,n;try{return a("parse json"),JSON.parse(e,y)}catch(e){throw d(e,{message:e.message,stack:e.stack})}}return function(e,t,n){if(e._body)return a("body already parsed"),void n();if(e.body=e.body||{},!u.hasBody(e))return a("skip empty body"),void n();if(a("content-type %j",e.headers["content-type"]),!v(e))return a("skip parsing"),void n();var p=function(e){try{return(i.parse(e).parameters.charset||"").toLowerCase()}catch(e){return}}(e)||"utf-8";if("utf-"!==p.slice(0,4))return a("invalid charset"),void n(o(415,'unsupported charset "'+p.toUpperCase()+'"',{charset:p,type:"charset.unsupported"}));s(e,t,n,m,a,{encoding:p,inflate:c,limit:r,verify:b})}};var p=/^[\x20\x09\x0a\x0d]*([^\x20\x09\x0a\x0d])/;function d(e,t){for(var r=Object.getOwnPropertyNames(e),n=0;n<r.length;n++){var i=r[n];"stack"!==i&&"message"!==i&&delete e[i]}return e.stack=t.stack.replace(e.message,t.message),e.message=t.message,e}},842:(e,t,r)=>{"use strict";var n=r(348),i=r(999)("body-parser:raw"),o=r(992),a=r(240);e.exports=function(e){var t=e||{},r=!1!==t.inflate,s="number"!=typeof t.limit?n.parse(t.limit||"100kb"):t.limit,u=t.type||"application/octet-stream",p=t.verify||!1;if(!1!==p&&"function"!=typeof p)throw new TypeError("option verify must be function");var d="function"!=typeof u?function(e){return function(t){return Boolean(a(t,e))}}(u):u;function c(e){return e}return function(e,t,n){return e._body?(i("body already parsed"),void n()):(e.body=e.body||{},a.hasBody(e)?(i("content-type %j",e.headers["content-type"]),d(e)?void o(e,t,n,c,i,{encoding:null,inflate:r,limit:s,verify:p}):(i("skip parsing"),void n())):(i("skip empty body"),void n()))}}},492:(e,t,r)=>{"use strict";var n=r(348),i=r(897),o=r(999)("body-parser:text"),a=r(992),s=r(240);e.exports=function(e){var t=e||{},r=t.defaultCharset||"utf-8",u=!1!==t.inflate,p="number"!=typeof t.limit?n.parse(t.limit||"100kb"):t.limit,d=t.type||"text/plain",c=t.verify||!1;if(!1!==c&&"function"!=typeof c)throw new TypeError("option verify must be function");var y="function"!=typeof d?function(e){return function(t){return Boolean(s(t,e))}}(d):d;function f(e){return e}return function(e,t,n){if(e._body)return o("body already parsed"),void n();if(e.body=e.body||{},!s.hasBody(e))return o("skip empty body"),void n();if(o("content-type %j",e.headers["content-type"]),!(e=>"text"==e.__forceParse)(e)&&!y(e))return o("skip parsing"),void n();var d=function(e){try{return(i.parse(e).parameters.charset||"").toLowerCase()}catch(e){return}}(e)||r;a(e,t,n,f,o,{encoding:d,inflate:u,limit:p,verify:c})}}},980:(e,t,r)=>{"use strict";var n=r(348),i=r(897),o=r(790),a=r(999)("body-parser:urlencoded"),s=r(622)("body-parser"),u=r(992),p=r(240);e.exports=function(e){var t=e||{};void 0===t.extended&&s("undefined extended: provide extended option");var r=!1!==t.extended,d=!1!==t.inflate,f="number"!=typeof t.limit?n.parse(t.limit||"100kb"):t.limit,l=t.type||"application/x-www-form-urlencoded",b=t.verify||!1;if(!1!==b&&"function"!=typeof b)throw new TypeError("option verify must be function");var v=r?function(e){var t=void 0!==e.parameterLimit?e.parameterLimit:1e3,r=y("qs");if(isNaN(t)||t<1)throw new TypeError("option parameterLimit must be a positive number");return isFinite(t)&&(t|=0),function(e){var n=c(e,t);if(void 0===n)throw a("too many parameters"),o(413,"too many parameters",{type:"parameters.too.many"});var i=Math.max(100,n);return a("parse extended urlencoding"),r(e,{allowPrototypes:!0,arrayLimit:i,depth:1/0,parameterLimit:t})}}(t):function(e){var t=void 0!==e.parameterLimit?e.parameterLimit:1e3,r=y("querystring");if(isNaN(t)||t<1)throw new TypeError("option parameterLimit must be a positive number");return isFinite(t)&&(t|=0),function(e){if(void 0===c(e,t))throw a("too many parameters"),o(413,"too many parameters",{type:"parameters.too.many"});return a("parse urlencoding"),r(e,void 0,void 0,{maxKeys:t})}}(t),m="function"!=typeof l?function(e){return function(t){return Boolean(p(t,e))}}(l):l;function h(e){return e.length?v(e):{}}return function(e,t,r){if(e._body)return a("body already parsed"),void r();if(e.body=e.body||{},!p.hasBody(e))return a("skip empty body"),void r();if(a("content-type %j",e.headers["content-type"]),!m(e))return a("skip parsing"),void r();var n=function(e){try{return(i.parse(e).parameters.charset||"").toLowerCase()}catch(e){return}}(e)||"utf-8";if("utf-8"!==n)return a("invalid charset"),void r(o(415,'unsupported charset "'+n.toUpperCase()+'"',{charset:n,type:"charset.unsupported"}));u(e,t,r,h,a,{debug:a,encoding:n,inflate:d,limit:f,verify:b})}};var d=Object.create(null);function c(e,t){for(var r=0,n=0;-1!==(n=e.indexOf("&",n));)if(n++,++r===t)return;return r}function y(e){var t=d[e];if(void 0!==t)return t.parse;switch(e){case"qs":t=r(656);break;case"querystring":t=r(871)}return d[e]=t,t.parse}},138:(e,t,r)=>{const n=r(814),i="MIDDWARE_PARSE",o=(e,t)=>{let{option:{log:{log:r}}}=Frame;return(o,a,s)=>{e.forceParse&&(o.__forceParse=t),n[t](e||{})(o,a,((e,t,r,n)=>o=>{o?(e._body=void 0,n.md(i,`${r} parse error`,o.type,o.message)):e.__parse||(e.__parse=r),t()})(o,s,t,r))}},a={json:o,text:o,raw:o,urlencoded:o};e.exports={middleware:e=>{let{params:t}=e;return(t.paraseType||["json"]).map((e=>{let r=a[e];return r?{position:"begin",method:"use",alias:e,matchPath:"",middleware:r(t[e],e)}:(log.mwn(i,`current not spport parase [${e}]`),null)})).filter((e=>!!e))}}},348:t=>{"use strict";t.exports=e},897:e=>{"use strict";e.exports=t},999:e=>{"use strict";e.exports=r},622:e=>{"use strict";e.exports=n},57:e=>{"use strict";e.exports=i},790:e=>{"use strict";e.exports=o},671:e=>{"use strict";e.exports=a},544:e=>{"use strict";e.exports=s},656:e=>{"use strict";e.exports=u},871:e=>{"use strict";e.exports=p},379:e=>{"use strict";e.exports=d},240:e=>{"use strict";e.exports=c},961:e=>{"use strict";e.exports=y},638:e=>{"use strict";e.exports=f}},b={},function e(t){var r=b[t];if(void 0!==r)return r.exports;var n=b[t]={exports:{}};return l[t](n,n.exports,e),n.exports}(138);var l,b})); //# sourceMappingURL=index-min.js.map