rsnext/packages/next/compiled/http-proxy/index.js

1 line
19 KiB
JavaScript
Raw Normal View History

module.exports=function(e,t){"use strict";var r={};function __webpack_require__(t){if(r[t]){return r[t].exports}var o=r[t]={i:t,l:false,exports:{}};e[t].call(o.exports,o,o.exports,__webpack_require__);o.l=true;return o.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(302)}return startup()}({184:function(e,t,r){var o=t,n=r(835),i=r(669)._extend,s=r(542);var a=/(^|,)\s*upgrade\s*($|,)/i,c=/^https|wss/;o.isSSL=c;o.setupOutgoing=function(e,t,r,f){e.port=t[f||"target"].port||(c.test(t[f||"target"].protocol)?443:80);["host","hostname","socketPath","pfx","key","passphrase","cert","ca","ciphers","secureProtocol"].forEach(function(r){e[r]=t[f||"target"][r]});e.method=t.method||r.method;e.headers=i({},r.headers);if(t.headers){i(e.headers,t.headers)}if(t.auth){e.auth=t.auth}if(t.ca){e.ca=t.ca}if(c.test(t[f||"target"].protocol)){e.rejectUnauthorized=typeof t.secure==="undefined"?true:t.secure}e.agent=t.agent||false;e.localAddress=t.localAddress;if(!e.agent){e.headers=e.headers||{};if(typeof e.headers.connection!=="string"||!a.test(e.headers.connection)){e.headers.connection="close"}}var u=t[f||"target"];var h=u&&t.prependPath!==false?u.path||"":"";var p=!t.toProxy?n.parse(r.url).path||"":r.url;p=!t.ignorePath?p:"";e.path=o.urlJoin(h,p);if(t.changeOrigin){e.headers.host=s(e.port,t[f||"target"].protocol)&&!hasPort(e.host)?e.host+":"+e.port:e.host}return e};o.setupSocket=function(e){e.setTimeout(0);e.setNoDelay(true);e.setKeepAlive(true,0);return e};o.getPort=function(e){var t=e.headers.host?e.headers.host.match(/:(\d+)/):"";return t?t[1]:o.hasEncryptedConnection(e)?"443":"80"};o.hasEncryptedConnection=function(e){return Boolean(e.connection.encrypted||e.connection.pair)};o.urlJoin=function(){var e=Array.prototype.slice.call(arguments),t=e.length-1,r=e[t],o=r.split("?"),n;e[t]=o.shift();n=[e.filter(Boolean).join("/").replace(/\/+/g,"/").replace("http:/","http://").replace("https:/","https://")];n.push.apply(n,o);return n.join("?")};o.rewriteCookieProperty=function rewriteCookieProperty(e,t,r){if(Array.isArray(e)){return e.map(function(e){return rewriteCookieProperty(e,t,r)})}return e.replace(new RegExp("(;\\s*"+r+"=)([^;]+)","i"),function(e,r,o){var n;if(o in t){n=t[o]}else if("*"in t){n=t["*"]}else{return e}if(n){return r+n}else{return""}})};function hasPort(e){return!!~e.indexOf(":")}},185:function(e){e.exports=require("next/dist/compiled/debug")},211:function(e){e.exports=require("https")},257:function(e,t,r){var o=r(605),n=r(211),i=r(184);e.exports={checkMethodAndHeader:function checkMethodAndHeader(e,t){if(e.method!=="GET"||!e.headers.upgrade){t.destroy();return true}if(e.headers.upgrade.toLowerCase()!=="websocket"){t.destroy();return true}},XHeaders:function XHeaders(e,t,r){if(!r.xfwd)return;var o={for:e.connection.remoteAddress||e.socket.remoteAddress,port:i.getPort(e),proto:i.hasEncryptedConnection(e)?"wss":"ws"};["for","port","proto"].forEach(function(t){e.headers["x-forwarded-"+t]=(e.headers["x-forwarded-"+t]||"")+(e.headers["x-forwarded-"+t]?",":"")+o[t]})},stream:function stream(e,t,r,s,a,c){var f=function(e,t){return Object.keys(t).reduce(function(e,r){var o=t[r];if(!Array.isArray(o)){e.push(r+": "+o);return e}for(var n=0;n<o.length;n++){e.push(r+": "+o[n])}return e},[e]).join("\r\n")+"\r\n\r\n"};i.setupSocket(t);if(s&&s.length)t.unshift(s);var u=(i.isSSL.test(r.target.protocol)?n:o).request(i.setupOutgoing(r.ssl||{},r,e));if(a){a.emit("proxyReqWs",u,e,t,r,s)}u.on("error",onOutgoingError);u.on("response",function(e){if(!e.upgrade){t.write(f("HTTP/"+e.httpVersion+" "+e.statusCode+" "+e.statusMessage,e.headers));e.pipe(t)}});u.on("upgrade",function(e,r,o){r.on("error",onOutgoingError);r.on("end",function(){a.emit("close",e,r,o)});t.on("error",function(){r.end()});i.setupSocket(r);if(o&&o.length)r.unshift(o);t.write(f("HTTP/1.1 101 Switching Protocols",e.headers));r.pipe(t).pipe(r);a.emit("open",r);a.emit("proxySocket",r)});return u.end();function onOutgoingError(r){if(c){c(r,e,t)}else{a.emit("error",r,e,t)}t.end()}}}},302:function(e,t,r){e.exports=r(461)},355:function(e){"use strict