rsnext/packages/next/compiled/compression/index.js

1 line
154 KiB
JavaScript
Raw Normal View History

module.exports=(()=>{var e={277:(e,a,i)=>{"use strict";var n=i(303);var s=i(27);e.exports=Accepts;function Accepts(e){if(!(this instanceof Accepts)){return new Accepts(e)}this.headers=e.headers;this.negotiator=new n(e)}Accepts.prototype.type=Accepts.prototype.types=function(e){var a=e;if(a&&!Array.isArray(a)){a=new Array(arguments.length);for(var i=0;i<a.length;i++){a[i]=arguments[i]}}if(!a||a.length===0){return this.negotiator.mediaTypes()}if(!this.headers.accept){return a[0]}var n=a.map(extToMime);var s=this.negotiator.mediaTypes(n.filter(validMime));var o=s[0];return o?a[n.indexOf(o)]:false};Accepts.prototype.encoding=Accepts.prototype.encodings=function(e){var a=e;if(a&&!Array.isArray(a)){a=new Array(arguments.length);for(var i=0;i<a.length;i++){a[i]=arguments[i]}}if(!a||a.length===0){return this.negotiator.encodings()}return this.negotiator.encodings(a)[0]||false};Accepts.prototype.charset=Accepts.prototype.charsets=function(e){var a=e;if(a&&!Array.isArray(a)){a=new Array(arguments.length);for(var i=0;i<a.length;i++){a[i]=arguments[i]}}if(!a||a.length===0){return this.negotiator.charsets()}return this.negotiator.charsets(a)[0]||false};Accepts.prototype.lang=Accepts.prototype.langs=Accepts.prototype.language=Accepts.prototype.languages=function(e){var a=e;if(a&&!Array.isArray(a)){a=new Array(arguments.length);for(var i=0;i<a.length;i++){a[i]=arguments[i]}}if(!a||a.length===0){return this.negotiator.languages()}return this.negotiator.languages(a)[0]||false};function extToMime(e){return e.indexOf("/")===-1?s.lookup(e):e}function validMime(e){return typeof e==="string"}},556:(e,a,i)=>{"use strict";var n=i(651);var s=/^text\/|\+(?:json|text|xml)$/i;var o=/^\s*([^;\s]*)(?:;|\s|$)/;e.exports=compressible;function compressible(e){if(!e||typeof e!=="string"){return false}var a=o.exec(e);var i=a&&a[1].toLowerCase();var c=n[i];if(c&&c.compressible!==undefined){return c.compressible}return s.test(i)||undefined}},638:(e,a,i)=>{"use strict";var n=i(277);var s=i(875).Buffer;var o=i(487);var c=i(556);var t=i(185)("compression");var p=i(475);var r=i(264);var l=i(761);e.exports=compression;e.exports.filter=shouldCompress;var u=/(?:^|,)\s*?no-transform\s*?(?:,|$)/;function compression(e){var a=e||{};var i=a.filter||shouldCompress;var s=o.parse(a.threshold);if(s==null){s=1024}return function compression(e,o,c){var u=false;var m;var d=[];var x;var v=o.end;var f=o.on;var b=o.write;o.flush=function flush(){if(x){x.flush()}};o.write=function write(e,a){if(u){return false}if(!this._header){this._implicitHeader()}return x?x.write(toBuffer(e,a)):b.call(this,e,a)};o.end=function end(e,a){if(u){return false}if(!this._header){if(!this.getHeader("Content-Length")){m=chunkLength(e,a)}this._implicitHeader()}if(!x){return v.call(this,e,a)}u=true;return e?x.end(toBuffer(e,a)):x.end()};o.on=function on(e,a){if(!d||e!=="drain"){return f.call(this,e,a)}if(x){return x.on(e,a)}d.push([e,a]);return this};function nocompress(e){t("no compression: %s",e);addListeners(o,f,d);d=null}p(o,function onResponseHeaders(){if(!i(e,o)){nocompress("filtered");return}if(!shouldTransform(e,o)){nocompress("no transform");return}r(o,"Accept-Encoding");if(Number(o.getHeader("Content-Length"))<s||m<s){nocompress("size below threshold");return}var c=o.getHeader("Content-Encoding")||"identity";if(c!=="identity"){nocompress("already encoded");return}if(e.method==="HEAD"){nocompress("HEAD request");return}var p=n(e);var u=p.encoding(["gzip","deflate","identity"]);if(u==="deflate"&&p.encoding(["gzip"])){u=p.encoding(["gzip","identity"])}if(!u||u==="identity"){nocompress("not acceptable");return}t("%s compression",u);x=u==="gzip"?l.createGzip(a):l.createDeflate(a);addListeners(x,x.on,d);o.setHeader("Content-Encoding",u);o.removeHeader("Content-Length");x.on("data",function onStreamData(e){if(b.call(o,e)===false){x.pause()}});x.on("end",function onStreamEnd(){v.call(o)});f.call(o,"drain",function onResponseDrain(){x.resume()})});c()}}function addListeners(e,a,i){for(var n=0;n<i.length;n++){a.apply(e,i[n])}}function chunkLength(e,a){if(!e){return 0}return!s.isBuffer(e)?s.byteLength(