You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-mitmproxy/addon/web/client/build/static/js/main.4248f977.chunk.js

2 lines
18 KiB
JavaScript

(this["webpackJsonpmitmproxy-client"]=this["webpackJsonpmitmproxy-client"]||[]).push([[0],{48:function(e,t,n){},53:function(e,t,n){"use strict";n.r(t);var s,i=n(0),r=n.n(i),o=n(20),a=n.n(o),c=(n(47),n(9)),l=n(10),h=n(19),d=n(18),u=n(41),j=n(7),b=n(11),f=(n(48),n(21)),O=n(16),p=n(12),v=n(33),w=n(23),x=n(1),S=function(e){Object(h.a)(n,e);var t=Object(d.a)(n);function n(e){var s;return Object(c.a)(this,n),(s=t.call(this,e)).state={show:!1,rule:{method:"ALL",url:"",action:1},haveRules:!1},s.handleClose=s.handleClose.bind(Object(O.a)(s)),s.handleShow=s.handleShow.bind(Object(O.a)(s)),s.handleSave=s.handleSave.bind(Object(O.a)(s)),s}return Object(l.a)(n,[{key:"handleClose",value:function(){this.setState({show:!1})}},{key:"handleShow",value:function(){this.setState({show:!0})}},{key:"handleSave",value:function(){var e=this.state.rule,t=[];e.url&&t.push({method:"ALL"===e.method?"":e.method,url:e.url,action:e.action}),this.props.onSave(t),this.handleClose(),this.setState({haveRules:!!t.length})}},{key:"render",value:function(){var e=this,t=this.state,n=t.rule,s=t.haveRules?"success":"primary";return Object(x.jsxs)("div",{children:[Object(x.jsx)(b.a,{variant:s,size:"sm",onClick:this.handleShow,children:"BreakPoint"}),Object(x.jsxs)(p.a,{show:this.state.show,onHide:this.handleClose,children:[Object(x.jsx)(p.a.Header,{closeButton:!0,children:Object(x.jsx)(p.a.Title,{children:"Set BreakPoint"})}),Object(x.jsxs)(p.a.Body,{children:[Object(x.jsxs)(j.a.Group,{as:v.a,children:[Object(x.jsx)(j.a.Label,{column:!0,sm:2,children:"Method"}),Object(x.jsx)(w.a,{sm:10,children:Object(x.jsxs)(j.a.Control,{as:"select",value:n.method,onChange:function(t){e.setState({rule:Object(f.a)(Object(f.a)({},n),{},{method:t.target.value})})},children:[Object(x.jsx)("option",{children:"ALL"}),Object(x.jsx)("option",{children:"GET"}),Object(x.jsx)("option",{children:"POST"}),Object(x.jsx)("option",{children:"PUT"}),Object(x.jsx)("option",{children:"DELETE"})]})})]}),Object(x.jsxs)(j.a.Group,{as:v.a,children:[Object(x.jsx)(j.a.Label,{column:!0,sm:2,children:"URL"}),Object(x.jsx)(w.a,{sm:10,children:Object(x.jsx)(j.a.Control,{value:n.url,onChange:function(t){e.setState({rule:Object(f.a)(Object(f.a)({},n),{},{url:t.target.value})})}})})]}),Object(x.jsxs)(j.a.Group,{as:v.a,children:[Object(x.jsx)(j.a.Label,{column:!0,sm:2,children:"Action"}),Object(x.jsx)(w.a,{sm:10,children:Object(x.jsxs)(j.a.Control,{as:"select",value:n.action,onChange:function(t){e.setState({rule:Object(f.a)(Object(f.a)({},n),{},{action:parseInt(t.target.value)})})},children:[Object(x.jsx)("option",{value:"1",children:"Request"}),Object(x.jsx)("option",{value:"2",children:"Response"}),Object(x.jsx)("option",{value:"3",children:"Both"})]})})]})]}),Object(x.jsxs)(p.a.Footer,{children:[Object(x.jsx)(b.a,{variant:"secondary",onClick:this.handleClose,children:"Close"}),Object(x.jsx)(b.a,{variant:"primary",onClick:this.handleSave,children:"Save"})]})]})]})}}]),n}(r.a.Component),y=n(39),E=n(34),m=n(42),g=n(40),R=function(e){return!!e&&(!!e.header&&(!!e.header["Content-Type"]&&/text|javascript|json/.test(e.header["Content-Type"].join(""))))};!function(e){e[e.REQUEST=1]="REQUEST",e[e.REQUEST_BODY=2]="REQUEST_BODY",e[e.RESPONSE=3]="RESPONSE",e[e.RESPONSE_BODY=4]="RESPONSE_BODY"}(s||(s={}));var C=function(){function e(t){Object(c.a)(this,e),this.no=void 0,this.id=void 0,this.waitIntercept=void 0,this.request=void 0,this.response=null,this.url=void 0,this._host="",this._path="",this._size="",this.no=++e.curNo,this.id=t.id,this.waitIntercept=t.waitIntercept,this.request=t.content,this.url=new URL(this.request.url)}return Object(l.a)(e,[{key:"addRequestBody",value:function(e){return this.waitIntercept=e.waitIntercept,this.request.body=e.content,this}},{key:"addResponse",value:function(e){return this.waitIntercept=e.waitIntercept,this.response=e.content,this}},{key:"addResponseBody",value:function(e){return this.waitIntercept=e.waitIntercept,this.response&&(this.response.body=e.content),this}},{key:"preview",value:function(){return{no:this.no,id:this.id,waitIntercept:this.waitIntercept,host:this.host,path:this.path,method:this.request.method,statusCode:this.response?String(this.response.statusCode):"(pending)",size:this.size}}},{key:"host",get:function(){if(this._host)return this._host;var e=this.url.host;return e.length>35&&(e=e.slice(0,35)+"..."),this._host=e,e}},{key:"path",get:function(){if(this._path)return this._path;var e=this.url.pathname+this.url.search;return e.length>65&&(e=e.slice(0,65)+"..."),this._path=e,e}},{key:"size",get:function(){return this.response&&this.response.header?(this._size||(this._size=function(e){return e&&e.header?(e.header["Content-Length"]?t=parseInt(e.header["Content-Length"][0]):e&&e.body&&(t=e.body.byteLength),t?isNaN(t)||t<=0?"0":t<1024?"".concat(t," B"):t<1048576?"".concat((t/1024).toFixed(2)," KB"):"".concat((t/1048576).toFixed(2)," MB"):"0"):"0";var t}(this.response)),this._size):"0"}}]),e}();C.curNo=0;var T,N=[s.REQUEST,s.REQUEST_BODY,s.RESPONSE,s.RESPONSE_BODY];!function(e){e[e.CHANGE_REQUEST=11]="CHANGE_REQUEST",e[e.CHANGE_RESPONSE=12]="CHANGE_RESPONSE",e[e.DROP_REQUEST=13]="DROP_REQUEST",e[e.DROP_RESPONSE=14]="DROP_RESPONSE",e[e.CHANGE_BREAK_POINT_RULES=21]="CHANGE_BREAK_POINT_RULES"}(T||(T={}));var k=function(e,t){if(e===T.DROP_REQUEST||e===T.DROP_RESPONSE){var n=new Uint8Array(38);return n[0]=1,n[1]=e,n.set((new TextEncoder).encode(t.id),2),n}var s,i;if(e===T.CHANGE_REQUEST){var r=t.request;i=r.body,s=Object(g.a)(r,["body"])}else{if(e!==T.CHANGE_RESPONSE)throw new Error("invalid message type");var o=t.response;i=o.body,s=Object(g.a)(o,["body"])}i instanceof ArrayBuffer&&(i=new Uint8Array(i));var a=i&&i.byteLength?i.byteLength:0;"Content-Encoding"in s.header&&delete s.header["Content-Encoding"],"Transfer-Encoding"in s.header&&delete s.header["Transfer-Encoding"],s.header["Content-Length"]=[String(a)];var c=(new TextEncoder).encode(JSON.stringify(s)),l=42+c.byteLength+4+a,h=new ArrayBuffer(l),d=new Uint8Array(h);d[0]=1,d[1]=e,d.set((new TextEncoder).encode(t.id),2),d.set(c,42),a&&d.set(i,42+c.byteLength+4);var u=new DataView(h);return u.setUint32(38,c.byteLength),u.setUint32(42+c.byteLength,a),d},_=function(e){Object(h.a)(n,e);var t=Object(d.a)(n);function n(e){var s;return Object(c.a)(this,n),(s=t.call(this,e)).state={show:!1,alertMsg:"",content:""},s.handleClose=s.handleClose.bind(Object(O.a)(s)),s.handleShow=s.handleShow.bind(Object(O.a)(s)),s.handleSave=s.handleSave.bind(Object(O.a)(s)),s}return Object(l.a)(n,[{key:"showAlert",value:function(e){this.setState({alertMsg:e})}},{key:"handleClose",value:function(){this.setState({show:!1})}},{key:"handleShow",value:function(){var e=this.props.flow,t="";t="request"===(e.response?"response":"request")?function(e){var t="".concat(e.method," ").concat(e.url),n=Object.keys(e.header).map((function(t){var n=e.header[t].join(" \t ");return"".concat(t,": ").concat(n)})).join("\n"),s="";return e.body&&R(e)&&(s=(new TextDecoder).decode(e.body)),"".concat(t,"\n\n").concat(n,"\n\n").concat(s)}(e.request):function(e){var t="".concat(e.statusCode),n=Object.keys(e.header).map((function(t){var n=e.header[t].join(" \t ");return"".concat(t,": ").concat(n)})).join("\n"),s="";return e.body&&R(e)&&(s=(new TextDecoder).decode(e.body)),"".concat(t,"\n\n").concat(n,"\n\n").concat(s)}(e.response),this.setState({show:!0,alertMsg:"",content:t})}},{key:"handleSave",value:function(){var e=this.props.flow.response?"response":"request",t=this.state.content;if("request"===e){var n=function(e){var t=e.indexOf("\n\n");if(!(t<=0)){var n=e.slice(0,t).split(" "),s=Object(E.a)(n,2),i=s[0],r=s[1];if(i&&r){var o=e.indexOf("\n\n",t+2);if(!(o<=0)){var a,c=e.slice(t+2,o),l={},h=Object(y.a)(c.split("\n"));try{for(h.s();!(a=h.n()).done;){var d=a.value.split(": "),u=Object(E.a)(d,2),j=u[0],b=u[1];if(!j||!b)return;l[j]=b.split(" \t ")}}catch(p){h.e(p)}finally{h.f()}var f,O=e.slice(o+2);return O&&(f=(new TextEncoder).encode(O)),{method:i,url:r,proto:"",header:l,body:f}}}}}(t);if(!n)return void this.showAlert("parse error");this.props.onChangeRequest(n),this.handleClose()}else{var s=function(e){var t=e.indexOf("\n\n");if(!(t<=0)){var n=e.slice(0,t),s=parseInt(n);if(!isNaN(s)){var i=e.indexOf("\n\n",t+2);if(!(i<=0)){var r,o=e.slice(t+2,i),a={},c=Object(y.a)(o.split("\n"));try{for(c.s();!(r=c.n()).done;){var l=r.value.split(": "),h=Object(E.a)(l,2),d=h[0],u=h[1];if(!d||!u)return;a[d]=u.split(" \t ")}}catch(f){c.e(f)}finally{c.f()}var j,b=e.slice(i+2);return b&&(j=(new TextEncoder).encode(b)),{statusCode:s,header:a,body:j}}}}}(t);if(!s)return void this.showAlert("parse error");this.props.onChangeResponse(s),this.handleClose()}}},{key:"render",value:function(){var e=this,t=this.props.flow;if(!t.waitIntercept)return null;var n=this.state.alertMsg,s=t.response?"response":"request";return Object(x.jsxs)("div",{className:"flow-wait-area",children:[Object(x.jsx)(b.a,{size:"sm",onClick:this.handleShow,children:"Edit"}),Object(x.jsx)(b.a,{size:"sm",onClick:function(){var n="response"===s?T.CHANGE_RESPONSE:T.CHANGE_REQUEST,i=k(n,t);e.props.onMessage(i)},children:"Continue"}),Object(x.jsx)(b.a,{size:"sm",onClick:function(){var n="response"===s?T.DROP_RESPONSE:T.DROP_REQUEST,i=k(n,t);e.props.onMessage(i)},children:"Drop"}),Object(x.jsxs)(p.a,{size:"lg",show:this.state.show,onHide:this.handleClose,children:[Object(x.jsx)(p.a.Header,{closeButton:!0,children:Object(x.jsxs)(p.a.Title,{children:["Edit ","request"===s?"Request":"Response"]})}),Object(x.jsxs)(p.a.Body,{children:[Object(x.jsx)(j.a.Group,{children:Object(x.jsx)(j.a.Control,{as:"textarea",rows:10,value:this.state.content,onChange:function(t){e.setState({content:t.target.value})}})}),n?Object(x.jsx)(m.a,{variant:"danger",children:n}):null]}),Object(x.jsxs)(p.a.Footer,{children:[Object(x.jsx)(b.a,{variant:"secondary",onClick:this.handleClose,children:"Close"}),Object(x.jsx)(b.a,{variant:"primary",onClick:this.handleSave,children:"Save"})]})]})]})}}]),n}(r.a.Component),L=function(e){Object(h.a)(n,e);var t=Object(d.a)(n);function n(){return Object(c.a)(this,n),t.apply(this,arguments)}return Object(l.a)(n,[{key:"shouldComponentUpdate",value:function(e){return e.isSelected!==this.props.isSelected||!function(e,t){if(e===t)return!0;var n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(var i=0;i<n.length;i++){var r=n[i];if(void 0===t[r]||e[r]!==t[r])return!1}return!0}(e.flow,this.props.flow)}},{key:"render",value:function(){var e=this,t=this.props.flow,n=[];return this.props.isSelected&&n.push("tr-selected"),t.waitIntercept&&n.push("tr-wait-intercept"),Object(x.jsxs)("tr",{className:n.length?n.join(" "):void 0,onClick:function(){e.props.onShowDetail()},children:[Object(x.jsx)("td",{children:t.no}),Object(x.jsx)("td",{children:t.host}),Object(x.jsx)("td",{children:t.path}),Object(x.jsx)("td",{children:t.method}),Object(x.jsx)("td",{children:t.statusCode}),Object(x.jsx)("td",{children:t.size})]})}}]),n}(r.a.Component),P=function(){function e(){Object(c.a)(this,e),this.items=void 0,this._map=void 0,this.filterText=void 0,this.filterTimer=void 0,this.num=void 0,this.max=void 0,this.items=[],this._map=new Map,this.filterText="",this.filterTimer=null,this.num=0,this.max=1e3}return Object(l.a)(e,[{key:"showList",value:function(){var e=this;return this.filterText?this.items.filter((function(t){return t.request.url.includes(e.filterText)})):this.items}},{key:"add",value:function(e){if(e.no=++this.num,this.items.push(e),this._map.set(e.id,e),this.items.length>this.max){var t=this.items.shift();t&&this._map.delete(t.id)}}},{key:"get",value:function(e){return this._map.get(e)}},{key:"changeFilter",value:function(e){this.filterText=e}},{key:"changeFilterLazy",value:function(e,t){var n=this;this.filterTimer&&(clearTimeout(this.filterTimer),this.filterTimer=null),this.filterTimer=setTimeout((function(){n.filterText=e,t()}),300)}},{key:"clear",value:function(){this.items=[],this._map=new Map}}]),e}(),U=function(e){Object(h.a)(n,e);var t=Object(d.a)(n);function n(e){var s;return Object(c.a)(this,n),(s=t.call(this,e)).flowMgr=void 0,s.ws=void 0,s.flowMgr=new P,s.state={flows:s.flowMgr.showList(),flow:null,flowTab:"Headers"},s.ws=null,s}return Object(l.a)(n,[{key:"componentDidMount",value:function(){this.initWs()}},{key:"componentWillUnmount",value:function(){this.ws&&this.ws.close()}},{key:"initWs",value:function(){var e,t=this;this.ws||(e=new URL(document.URL).host,this.ws=new WebSocket("ws://".concat(e,"/echo")),this.ws.binaryType="arraybuffer",this.ws.onopen=function(){console.log("OPEN")},this.ws.onclose=function(){console.log("CLOSE")},this.ws.onmessage=function(e){var n=function(e){if(e.byteLength<39)return null;var t=new Int8Array(e.slice(0,39));if(1!==t[0])return null;var n=t[1];if(!N.includes(n))return null;var i={type:n,id:(new TextDecoder).decode(e.slice(2,38)),waitIntercept:1===t[38]};if(39===e.byteLength)return i;if(n===s.REQUEST_BODY||n===s.RESPONSE_BODY)return i.content=e.slice(39),i;var r,o=(new TextDecoder).decode(e.slice(39));try{r=JSON.parse(o)}catch(a){return null}return i.content=r,i}(e.data);if(n){if(n.type===s.REQUEST){var i=new C(n);t.flowMgr.add(i),t.setState({flows:t.flowMgr.showList()})}else if(n.type===s.REQUEST_BODY){var r=t.flowMgr.get(n.id);if(!r)return;r.addRequestBody(n),t.setState({flows:t.state.flows})}else if(n.type===s.RESPONSE){var o=t.flowMgr.get(n.id);if(!o)return;o.addResponse(n),t.setState({flows:t.state.flows})}else if(n.type===s.RESPONSE_BODY){var a=t.flowMgr.get(n.id);if(!a||!a.response)return;a.addResponseBody(n),t.setState({flows:t.state.flows})}}else console.error("parse error:",e.data)},this.ws.onerror=function(e){console.log("ERROR:",e)})}},{key:"renderFlow",value:function(){var e=this,t=this.state,n=t.flow,s=t.flowTab;if(!n)return null;var i=n.request,r=n.response||{};return Object(x.jsxs)("div",{className:"flow-detail",children:[Object(x.jsxs)("div",{className:"header-tabs",children:[Object(x.jsx)("span",{onClick:function(){e.setState({flow:null})},children:"x"}),Object(x.jsx)("span",{className:"Headers"===s?"selected":void 0,onClick:function(){e.setState({flowTab:"Headers"})},children:"Headers"}),Object(x.jsx)("span",{className:"Preview"===s?"selected":void 0,onClick:function(){e.setState({flowTab:"Preview"})},children:"Preview"}),Object(x.jsx)("span",{className:"Response"===s?"selected":void 0,onClick:function(){e.setState({flowTab:"Response"})},children:"Response"}),Object(x.jsx)(_,{flow:n,onChangeRequest:function(t){n.request.method=t.method,n.request.url=t.url,n.request.header=t.header,R(n.request)&&(n.request.body=t.body),e.setState({flows:e.state.flows})},onChangeResponse:function(t){n.response||(n.response={}),n.response.statusCode=t.statusCode,n.response.header=t.header,R(n.response)&&(n.response.body=t.body),e.setState({flows:e.state.flows})},onMessage:function(t){e.ws&&e.ws.send(t),n.waitIntercept=!1,e.setState({flows:e.state.flows})}})]}),Object(x.jsxs)("div",{style:{padding:"20px"},children:["Headers"!==s?null:Object(x.jsxs)("div",{children:[Object(x.jsxs)("div",{className:"header-block",children:[Object(x.jsx)("p",{children:"General"}),Object(x.jsxs)("div",{className:"header-block-content",children:[Object(x.jsxs)("p",{children:["Request URL: ",i.url]}),Object(x.jsxs)("p",{children:["Request Method: ",i.method]}),Object(x.jsxs)("p",{children:["Status Code: ","".concat(r.statusCode||"(pending)")]})]})]}),r.header?Object(x.jsxs)("div",{className:"header-block",children:[Object(x.jsx)("p",{children:"Response Headers"}),Object(x.jsx)("div",{className:"header-block-content",children:Object.keys(r.header).map((function(e){return Object(x.jsxs)("p",{children:[e,": ",r.header[e].join(" ")]},e)}))})]}):null,Object(x.jsxs)("div",{className:"header-block",children:[Object(x.jsx)("p",{children:"Request Headers"}),Object(x.jsx)("div",{className:"header-block-content",children:i.header?Object.keys(i.header).map((function(e){return Object(x.jsxs)("p",{children:[e,": ",i.header[e].join(" ")]},e)})):null})]}),i.body&&i.body.byteLength?Object(x.jsxs)("div",{className:"header-block",children:[Object(x.jsx)("p",{children:"Request Body"}),Object(x.jsx)("div",{className:"header-block-content",children:Object(x.jsx)("p",{children:R(i)?(new TextDecoder).decode(i.body):"Not text"})})]}):null]}),"Response"!==s?null:r.body&&r.body.byteLength?R(r)?Object(x.jsx)("div",{children:(new TextDecoder).decode(r.body)}):Object(x.jsx)("div",{children:"Not text response"}):Object(x.jsx)("div",{children:"No response"})]})]})}},{key:"render",value:function(){var e=this,t=this.state.flows;return Object(x.jsxs)("div",{className:"main-table-wrap",children:[Object(x.jsxs)("div",{className:"top-control",children:[Object(x.jsx)("div",{children:Object(x.jsx)(b.a,{size:"sm",onClick:function(){e.flowMgr.clear(),e.setState({flows:e.flowMgr.showList(),flow:null})},children:"Clear"})}),Object(x.jsx)("div",{children:Object(x.jsx)(j.a.Control,{size:"sm",placeholder:"Filter",onChange:function(t){var n=t.target.value;e.flowMgr.changeFilterLazy(n,(function(){e.setState({flows:e.flowMgr.showList()})}))}})}),Object(x.jsx)(S,{onSave:function(t){var n=function(e,t){if(e!==T.CHANGE_BREAK_POINT_RULES)throw new Error("invalid message type");var n=(new TextEncoder).encode(JSON.stringify(t)),s=new Uint8Array(2+n.byteLength);return s[0]=1,s[1]=e,s.set(n,2),s}(T.CHANGE_BREAK_POINT_RULES,t);e.ws&&e.ws.send(n)}})]}),Object(x.jsxs)(u.a,{striped:!0,bordered:!0,size:"sm",children:[Object(x.jsx)("thead",{children:Object(x.jsxs)("tr",{children:[Object(x.jsx)("th",{children:"No"}),Object(x.jsx)("th",{children:"Host"}),Object(x.jsx)("th",{children:"Path"}),Object(x.jsx)("th",{children:"Method"}),Object(x.jsx)("th",{children:"Status"}),Object(x.jsx)("th",{children:"Size"})]})}),Object(x.jsx)("tbody",{children:t.map((function(t){var n=t.preview();return Object(x.jsx)(L,{flow:n,isSelected:!(!e.state.flow||e.state.flow.id!==n.id),onShowDetail:function(){e.setState({flow:t})}},n.id)}))})]}),this.renderFlow()]})}}]),n}(r.a.Component),B=function(e){e&&e instanceof Function&&n.e(3).then(n.bind(null,55)).then((function(t){var n=t.getCLS,s=t.getFID,i=t.getFCP,r=t.getLCP,o=t.getTTFB;n(e),s(e),i(e),r(e),o(e)}))};a.a.render(Object(x.jsx)(r.a.StrictMode,{children:Object(x.jsx)(U,{})}),document.getElementById("root")),B()}},[[53,1,2]]]);
//# sourceMappingURL=main.4248f977.chunk.js.map