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/web/client/build/static/js/main.2abbef8f.chunk.js

2 lines
29 KiB
JavaScript

(this["webpackJsonpmitmproxy-client"]=this["webpackJsonpmitmproxy-client"]||[]).push([[0],{59:function(e,t,s){},65:function(e,t,s){"use strict";s.r(t);var n=s(1),i=s.n(n),r=s(20),o=s.n(r),a=(s(58),s(7)),c=s(8),l=s(15),d=s(14),h=s(52),u=s(10),p=s(13),j=(s(59),s(2)),v=s(22),b=s(16),y=s(43),f=s(30),O=s(0),w=function(e){Object(l.a)(s,e);var t=Object(d.a)(s);function s(e){var n;return Object(a.a)(this,s),(n=t.call(this,e)).state={show:!1,rule:{method:"ALL",url:"",action:1},haveRules:!1},n.handleClose=n.handleClose.bind(Object(v.a)(n)),n.handleShow=n.handleShow.bind(Object(v.a)(n)),n.handleSave=n.handleSave.bind(Object(v.a)(n)),n}return Object(c.a)(s,[{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,s=t.rule,n=t.haveRules?"success":"primary";return Object(O.jsxs)("div",{children:[Object(O.jsx)(p.a,{variant:n,size:"sm",onClick:this.handleShow,children:"BreakPoint"}),Object(O.jsxs)(b.a,{show:this.state.show,onHide:this.handleClose,children:[Object(O.jsx)(b.a.Header,{closeButton:!0,children:Object(O.jsx)(b.a.Title,{children:"Set BreakPoint"})}),Object(O.jsxs)(b.a.Body,{children:[Object(O.jsxs)(u.a.Group,{as:y.a,children:[Object(O.jsx)(u.a.Label,{column:!0,sm:2,children:"Method"}),Object(O.jsx)(f.a,{sm:10,children:Object(O.jsxs)(u.a.Control,{as:"select",value:s.method,onChange:function(t){e.setState({rule:Object(j.a)(Object(j.a)({},s),{},{method:t.target.value})})},children:[Object(O.jsx)("option",{children:"ALL"}),Object(O.jsx)("option",{children:"GET"}),Object(O.jsx)("option",{children:"POST"}),Object(O.jsx)("option",{children:"PUT"}),Object(O.jsx)("option",{children:"DELETE"})]})})]}),Object(O.jsxs)(u.a.Group,{as:y.a,children:[Object(O.jsx)(u.a.Label,{column:!0,sm:2,children:"URL"}),Object(O.jsx)(f.a,{sm:10,children:Object(O.jsx)(u.a.Control,{value:s.url,onChange:function(t){e.setState({rule:Object(j.a)(Object(j.a)({},s),{},{url:t.target.value})})}})})]}),Object(O.jsxs)(u.a.Group,{as:y.a,children:[Object(O.jsx)(u.a.Label,{column:!0,sm:2,children:"Action"}),Object(O.jsx)(f.a,{sm:10,children:Object(O.jsxs)(u.a.Control,{as:"select",value:s.action,onChange:function(t){e.setState({rule:Object(j.a)(Object(j.a)({},s),{},{action:parseInt(t.target.value)})})},children:[Object(O.jsx)("option",{value:"1",children:"Request"}),Object(O.jsx)("option",{value:"2",children:"Response"}),Object(O.jsx)("option",{value:"3",children:"Both"})]})})]})]}),Object(O.jsxs)(b.a.Footer,{children:[Object(O.jsx)(p.a,{variant:"secondary",onClick:this.handleClose,children:"Close"}),Object(O.jsx)(p.a,{variant:"primary",onClick:this.handleSave,children:"Save"})]})]})]})}}]),s}(i.a.Component),x=function(e){return!!e&&(!!e.header&&(!!e.header["Content-Type"]&&/text|javascript|json|x-www-form-urlencoded|xml|form-data/.test(e.header["Content-Type"].join(""))))},m=function(e){return e?isNaN(e)||e<=0?"0":e<1024?"".concat(e," B"):e<1048576?"".concat((e/1024).toFixed(2)," KB"):"".concat((e/1048576).toFixed(2)," MB"):"0"},S=function(e){for(var t="",s=new Uint8Array(e),n=s.byteLength,i=0;i<n;i++)t+=String.fromCharCode(s[i]);return btoa(t)},R=function(e){var t="",s=new Uint8Array(e),n=s.byteLength,i="";t+="00000000: ";for(var r=0;r<n;r++)t+=s[r].toString(16).padStart(2,"0")+" ",s[r]>=32&&s[r]<=126?i+=String.fromCharCode(s[r]):i+=".",(r+1)%16===0?(t+=" "+i,i="",t+="\n".concat((r+1).toString(16).padStart(8,"0"),": ")):(r+1)%8===0&&(t+=" ");if(i.length>0){for(var o=i.length;o<16;o++)t+=" ",(o+1)%8===0&&(t+=" ");t+=" "+i}return t};var g,E=function(e){Object(l.a)(s,e);var t=Object(d.a)(s);function s(){return Object(a.a)(this,s),t.apply(this,arguments)}return Object(c.a)(s,[{key:"shouldComponentUpdate",value:function(e){return e.isSelected!==this.props.isSelected||!function(e,t){if(e===t)return!0;var s=Object.keys(e),n=Object.keys(t);if(s.length!==n.length)return!1;for(var i=0;i<s.length;i++){var r=s[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,s=[];return this.props.isSelected&&s.push("tr-selected"),t.waitIntercept&&s.push("tr-wait-intercept"),Object(O.jsxs)("tr",{className:s.length?s.join(" "):void 0,onClick:function(){e.props.onShowDetail()},children:[Object(O.jsx)("td",{children:t.no}),Object(O.jsx)("td",{children:t.method}),Object(O.jsx)("td",{children:t.host}),Object(O.jsx)("td",{children:t.path}),Object(O.jsx)("td",{children:t.contentType}),Object(O.jsx)("td",{children:t.statusCode}),Object(O.jsx)("td",{children:t.size}),Object(O.jsx)("td",{children:t.costTime})]})}}]),s}(i.a.Component),C=s(26),B=s(49),T=s.n(B),_=s(50),N=s.n(_),k=s(46),q=s.n(k),L=s(47),P=s(6),U=s(53),D=s(3);!function(e){e[e.CONN=0]="CONN",e[e.CONN_CLOSE=5]="CONN_CLOSE",e[e.REQUEST=1]="REQUEST",e[e.REQUEST_BODY=2]="REQUEST_BODY",e[e.RESPONSE=3]="RESPONSE",e[e.RESPONSE_BODY=4]="RESPONSE_BODY"}(g||(g={}));var M,A=[g.CONN,g.CONN_CLOSE,g.REQUEST,g.REQUEST_BODY,g.RESPONSE,g.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"}(M||(M={}));var I=function(e,t){if(e===M.DROP_REQUEST||e===M.DROP_RESPONSE){var s=new Uint8Array(38);return s[0]=1,s[1]=e,s.set((new TextEncoder).encode(t.id),2),s}var n,i;if(e===M.CHANGE_REQUEST){var r=t.request;i=r.body,n=Object(D.a)(r,["body"])}else{if(e!==M.CHANGE_RESPONSE)throw new Error("invalid message type");var o=t.response;i=o.body,n=Object(D.a)(o,["body"])}i instanceof ArrayBuffer&&(i=new Uint8Array(i));var a=i&&i.byteLength?i.byteLength:0;"Content-Encoding"in n.header&&delete n.header["Content-Encoding"],"Transfer-Encoding"in n.header&&delete n.header["Transfer-Encoding"],n.header["Content-Length"]=[String(a)];var c=(new TextEncoder).encode(JSON.stringify(n)),l=42+c.byteLength+4+a,d=new ArrayBuffer(l),h=new Uint8Array(d);h[0]=1,h[1]=e,h.set((new TextEncoder).encode(t.id),2),h.set(c,42),a&&h.set(i,42+c.byteLength+4);var u=new DataView(d);return u.setUint32(38,c.byteLength),u.setUint32(42+c.byteLength,a),h},H=function(e){Object(l.a)(s,e);var t=Object(d.a)(s);function s(e){var n;return Object(a.a)(this,s),(n=t.call(this,e)).state={show:!1,alertMsg:"",content:""},n.handleClose=n.handleClose.bind(Object(v.a)(n)),n.handleShow=n.handleShow.bind(Object(v.a)(n)),n.handleSave=n.handleSave.bind(Object(v.a)(n)),n}return Object(c.a)(s,[{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),s=Object.keys(e.header).map((function(t){var s=e.header[t].join(" \t ");return"".concat(t,": ").concat(s)})).join("\n"),n="";return e.body&&x(e)&&(n=(new TextDecoder).decode(e.body)),"".concat(t,"\n\n").concat(s,"\n\n").concat(n)}(e.request):function(e){var t="".concat(e.statusCode),s=Object.keys(e.header).map((function(t){var s=e.header[t].join(" \t ");return"".concat(t,": ").concat(s)})).join("\n"),n="";return e.body&&x(e)&&(n=(new TextDecoder).decode(e.body)),"".concat(t,"\n\n").concat(s,"\n\n").concat(n)}(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 s=function(e){var t=e.indexOf("\n\n");if(!(t<=0)){var s=e.slice(0,t).split(" "),n=Object(P.a)(s,2),i=n[0],r=n[1];if(i&&r){var o=e.indexOf("\n\n",t+2);if(!(o<=0)){var a,c=e.slice(t+2,o),l={},d=Object(L.a)(c.split("\n"));try{for(d.s();!(a=d.n()).done;){var h=a.value.split(": "),u=Object(P.a)(h,2),p=u[0],j=u[1];if(!p||!j)return;l[p]=j.split(" \t ")}}catch(y){d.e(y)}finally{d.f()}var v,b=e.slice(o+2);return b&&(v=(new TextEncoder).encode(b)),{method:i,url:r,proto:"",header:l,body:v}}}}}(t);if(!s)return void this.showAlert("parse error");this.props.onChangeRequest(s),this.handleClose()}else{var n=function(e){var t=e.indexOf("\n\n");if(!(t<=0)){var s=e.slice(0,t),n=parseInt(s);if(!isNaN(n)){var i=e.indexOf("\n\n",t+2);if(!(i<=0)){var r,o=e.slice(t+2,i),a={},c=Object(L.a)(o.split("\n"));try{for(c.s();!(r=c.n()).done;){var l=r.value.split(": "),d=Object(P.a)(l,2),h=d[0],u=d[1];if(!h||!u)return;a[h]=u.split(" \t ")}}catch(v){c.e(v)}finally{c.f()}var p,j=e.slice(i+2);return j&&(p=(new TextEncoder).encode(j)),{statusCode:n,header:a,body:p}}}}}(t);if(!n)return void this.showAlert("parse error");this.props.onChangeResponse(n),this.handleClose()}}},{key:"render",value:function(){var e=this,t=this.props.flow;if(!t.waitIntercept)return null;var s=this.state.alertMsg,n=t.response?"response":"request";return Object(O.jsxs)("div",{className:"flow-wait-area",children:[Object(O.jsx)(p.a,{size:"sm",onClick:this.handleShow,children:"Edit"}),Object(O.jsx)(p.a,{size:"sm",onClick:function(){var s="response"===n?M.CHANGE_RESPONSE:M.CHANGE_REQUEST,i=I(s,t);e.props.onMessage(i)},children:"Continue"}),Object(O.jsx)(p.a,{size:"sm",onClick:function(){var s="response"===n?M.DROP_RESPONSE:M.DROP_REQUEST,i=I(s,t);e.props.onMessage(i)},children:"Drop"}),Object(O.jsxs)(b.a,{size:"lg",show:this.state.show,onHide:this.handleClose,children:[Object(O.jsx)(b.a.Header,{closeButton:!0,children:Object(O.jsxs)(b.a.Title,{children:["Edit ","request"===n?"Request":"Response"]})}),Object(O.jsxs)(b.a.Body,{children:[Object(O.jsx)(u.a.Group,{children:Object(O.jsx)(u.a.Control,{as:"textarea",rows:10,value:this.state.content,onChange:function(t){e.setState({content:t.target.value})}})}),s?Object(O.jsx)(U.a,{variant:"danger",children:s}):null]}),Object(O.jsxs)(b.a.Footer,{children:[Object(O.jsx)(p.a,{variant:"secondary",onClick:this.handleClose,children:"Close"}),Object(O.jsx)(p.a,{variant:"primary",onClick:this.handleSave,children:"Save"})]})]})]})}}]),s}(i.a.Component),z=function(e){Object(l.a)(s,e);var t=Object(d.a)(s);function s(e){var n;return Object(a.a)(this,s),(n=t.call(this,e)).state={flowTab:"Detail",copied:!1,requestBodyViewTab:"Raw",responseBodyLineBreak:!1},n}return Object(c.a)(s,[{key:"preview",value:function(){var e=this.props.flow;if(!e)return null;var t=e.response;if(!t)return null;if(!t.body||!t.body.byteLength)return Object(O.jsx)("div",{style:{color:"gray"},children:"No response"});var s=e.previewResponseBody();return s?"image"===s.type?Object(O.jsx)("img",{src:"data:image/png;base64,".concat(s.data)}):"json"===s.type?Object(O.jsx)("div",{children:Object(O.jsx)(q.a,{data:s.data,keyStyle:"color: rgb(130,40,144);",stringStyle:"color: rgb(153,68,60);",valueStyle:"color: rgb(25,1,199);",booleanStyle:"color: rgb(94,105,192);"})}):Object(O.jsx)("div",{style:{color:"gray"},children:"Not support preview"}):Object(O.jsx)("div",{style:{color:"gray"},children:"Not support preview"})}},{key:"requestBodyPreview",value:function(){var e=this.props.flow;if(!e)return null;var t=e.previewRequestBody();return t?"json"===t.type?Object(O.jsx)("div",{children:Object(O.jsx)(q.a,{data:t.data,keyStyle:"color: rgb(130,40,144);",stringStyle:"color: rgb(153,68,60);",valueStyle:"color: rgb(25,1,199);",booleanStyle:"color: rgb(94,105,192);"})}):"binary"===t.type?Object(O.jsx)("div",{children:Object(O.jsx)("pre",{children:t.data})}):Object(O.jsx)("div",{style:{color:"gray"},children:"Not support preview"}):Object(O.jsx)("div",{style:{color:"gray"},children:"Not support preview"})}},{key:"hexview",value:function(){var e=this.props.flow;if(!e)return null;var t=e.response;return t?t.body&&t.body.byteLength?Object(O.jsx)("pre",{children:e.hexviewResponseBody()}):Object(O.jsx)("div",{style:{color:"gray"},children:"No response"}):null}},{key:"detail",value:function(){var e=this.props.flow;if(!e)return null;var t=e.getConn();return t?Object(O.jsxs)("div",{children:[Object(O.jsxs)("div",{className:"header-block",children:[Object(O.jsx)("p",{children:"Server Connection"}),Object(O.jsxs)("div",{className:"header-block-content",children:[Object(O.jsxs)("p",{children:["Address: ",t.serverConn.address]}),Object(O.jsxs)("p",{children:["Resolved Address: ",t.serverConn.peername]})]})]}),Object(O.jsxs)("div",{className:"header-block",children:[Object(O.jsx)("p",{children:"Client Connection"}),Object(O.jsx)("div",{className:"header-block-content",children:Object(O.jsxs)("p",{children:["Address: ",t.clientConn.address]})})]})]}):null}},{key:"render",value:function(){var e=this;if(!this.props.flow)return null;var t=this.props.flow,s=this.state.flowTab,n=t.request,i=t.response||{},r=[];return t.url&&t.url.search&&t.url.searchParams.forEach((function(e,t){r.push({key:t,value:e})})),Object(O.jsxs)("div",{className:"flow-detail",children:[Object(O.jsxs)("div",{className:"header-tabs",children:[Object(O.jsx)("span",{onClick:function(){e.props.onClose()},children:"x"}),Object(O.jsx)("span",{className:"Detail"===s?"selected":void 0,onClick:function(){e.setState({flowTab:"Detail"})},children:"Detail"}),Object(O.jsx)("span",{className:"Headers"===s?"selected":void 0,onClick:function(){e.setState({flowTab:"Headers"})},children:"Headers"}),Object(O.jsx)("span",{className:"Preview"===s?"selected":void 0,onClick:function(){e.setState({flowTab:"Preview"})},children:"Preview"}),Object(O.jsx)("span",{className:"Response"===s?"selected":void 0,onClick:function(){e.setState({flowTab:"Response"})},children:"Response"}),Object(O.jsx)("span",{className:"Hexview"===s?"selected":void 0,onClick:function(){e.setState({flowTab:"Hexview"})},children:"Hexview"}),Object(O.jsx)(H,{flow:t,onChangeRequest:function(s){t.request.method=s.method,t.request.url=s.url,t.request.header=s.header,x(t.request)&&(t.request.body=s.body),e.props.onReRenderFlows()},onChangeResponse:function(s){t.response||(t.response={}),t.response.statusCode=s.statusCode,t.response.header=s.header,x(t.response)&&(t.response.body=s.body),e.props.onReRenderFlows()},onMessage:function(s){e.props.onMessage(s),t.waitIntercept=!1,e.props.onReRenderFlows()}})]}),Object(O.jsxs)("div",{style:{padding:"20px"},children:["Headers"!==s?null:Object(O.jsxs)("div",{children:[Object(O.jsx)("p",{children:Object(O.jsx)(p.a,{size:"sm",variant:this.state.copied?"success":"primary",disabled:this.state.copied,onClick:function(){var s=T()({url:t.request.url,method:t.request.method,headers:Object.keys(t.request.header).reduce((function(e,s){return e[s]=t.request.header[s][0],e}),{}),body:t.requestBody()});N()(s),e.setState({copied:!0},(function(){setTimeout((function(){e.setState({copied:!1})}),1e3)}))},children:this.state.copied?"Copied":"Copy as cURL"})}),Object(O.jsxs)("div",{className:"header-block",children:[Object(O.jsx)("p",{children:"General"}),Object(O.jsxs)("div",{className:"header-block-content",children:[Object(O.jsxs)("p",{children:["Request URL: ",n.url]}),Object(O.jsxs)("p",{children:["Request Method: ",n.method]}),Object(O.jsxs)("p",{children:["Status Code: ","".concat(i.statusCode||"(pending)")]})]})]}),i.header?Object(O.jsxs)("div",{className:"header-block",children:[Object(O.jsx)("p",{children:"Response Headers"}),Object(O.jsx)("div",{className:"header-block-content",children:Object.keys(i.header).map((function(e){return Object(O.jsxs)("p",{children:[e,": ",i.header[e].join(" ")]},e)}))})]}):null,Object(O.jsxs)("div",{className:"header-block",children:[Object(O.jsx)("p",{children:"Request Headers"}),Object(O.jsx)("div",{className:"header-block-content",children:n.header?Object.keys(n.header).map((function(e){return Object(O.jsxs)("p",{children:[e,": ",n.header[e].join(" ")]},e)})):null})]}),r.length?Object(O.jsxs)("div",{className:"header-block",children:[Object(O.jsx)("p",{children:"Query String Parameters"}),Object(O.jsx)("div",{className:"header-block-content",children:r.map((function(e){var t=e.key,s=e.value;return Object(O.jsxs)("p",{children:[t,": ",s]},t)}))})]}):null,n.body&&n.body.byteLength?Object(O.jsxs)("div",{className:"header-block",children:[Object(O.jsx)("p",{children:"Request Body"}),Object(O.jsx)("div",{className:"header-block-content",children:Object(O.jsxs)("div",{children:[Object(O.jsxs)("div",{className:"request-body-detail",style:{marginBottom:"15px"},children:[Object(O.jsx)("span",{className:"Raw"===this.state.requestBodyViewTab?"selected":void 0,onClick:function(){e.setState({requestBodyViewTab:"Raw"})},children:"Raw"}),Object(O.jsx)("span",{className:"Preview"===this.state.requestBodyViewTab?"selected":void 0,onClick:function(){e.setState({requestBodyViewTab:"Preview"})},children:"Preview"})]}),"Raw"!==this.state.requestBodyViewTab?null:Object(O.jsx)("div",{children:t.isTextRequest()?t.requestBody():Object(O.jsx)("span",{style:{color:"gray"},children:"Not text Request"})}),"Preview"!==this.state.requestBodyViewTab?null:Object(O.jsx)("div",{children:this.requestBodyPreview()})]})})]}):null]}),"Response"!==s?null:i.body&&i.body.byteLength?t.isTextResponse()?Object(O.jsxs)("div",{children:[Object(O.jsx)("div",{style:{marginBottom:"20px"},children:Object(O.jsx)(C.a,{inline:!0,type:"checkbox",checked:this.state.responseBodyLineBreak,onChange:function(t){e.setState({responseBodyLineBreak:t.target.checked})},label:"\u81ea\u52a8\u6362\u884c"})}),Object(O.jsx)("div",{style:{whiteSpace:this.state.responseBodyLineBreak?"pre-wrap":"pre"},children:t.responseBody()})]}):Object(O.jsx)("div",{style:{color:"gray"},children:"Not text response"}):Object(O.jsx)("div",{style:{color:"gray"},children:"No response"}),"Preview"!==s?null:Object(O.jsx)("div",{children:this.preview()}),"Hexview"!==s?null:Object(O.jsx)("div",{children:this.hexview()}),"Detail"!==s?null:Object(O.jsx)("div",{children:this.detail()})]})]})}}]),s}(i.a.Component),Q=function(){function e(t,s){Object(a.a)(this,e),this.no=void 0,this.id=void 0,this.connId=void 0,this.waitIntercept=void 0,this.request=void 0,this.response=null,this.url=void 0,this.path=void 0,this._size=0,this.size="0",this.headerContentLengthExist=!1,this.contentType="",this.startTime=Date.now(),this.endTime=0,this.costTime="(pending)",this.status=g.REQUEST,this._isTextRequest=void 0,this._isTextResponse=void 0,this._requestBody=void 0,this._hexviewRequestBody=null,this._responseBody=void 0,this._previewResponseBody=null,this._previewRequestBody=null,this._hexviewResponseBody=null,this.connMgr=void 0,this.conn=void 0,this.no=++e.curNo,this.id=t.id,this.waitIntercept=t.waitIntercept;var n=t.content;this.connId=n.connId,this.request=n.request,this.url=new URL(this.request.url),this.path=this.url.pathname+this.url.search,this._isTextRequest=null,this._isTextResponse=null,this._requestBody=null,this._responseBody=null,this.connMgr=s}return Object(c.a)(e,[{key:"addRequestBody",value:function(e){return this.status=g.REQUEST_BODY,this.waitIntercept=e.waitIntercept,this.request.body=e.content,this}},{key:"addResponse",value:function(e){return this.status=g.RESPONSE,this.waitIntercept=e.waitIntercept,this.response=e.content,this.response&&this.response.header&&(null!=this.response.header["Content-Type"]&&(this.contentType=this.response.header["Content-Type"][0].split(";")[0],this.contentType.includes("javascript")&&(this.contentType="javascript")),null!=this.response.header["Content-Length"]&&(this.headerContentLengthExist=!0,this._size=parseInt(this.response.header["Content-Length"][0]),this.size=m(this._size))),this}},{key:"addResponseBody",value:function(e){return this.status=g.RESPONSE_BODY,this.waitIntercept=e.waitIntercept,this.response&&(this.response.body=e.content),this.endTime=Date.now(),this.costTime=String(this.endTime-this.startTime)+" ms",!this.headerContentLengthExist&&this.response&&this.response.body&&(this._size=this.response.body.byteLength,this.size=m(this._size)),this}},{key:"preview",value:function(){return{no:this.no,id:this.id,waitIntercept:this.waitIntercept,host:this.url.host,path:this.path,method:this.request.method,statusCode:this.response?String(this.response.statusCode):"(pending)",size:this.size,costTime:this.costTime,contentType:this.contentType}}},{key:"isTextRequest",value:function(){return null!==this._isTextRequest||(this._isTextRequest=x(this.request)),this._isTextRequest}},{key:"requestBody",value:function(){return null!==this._requestBody?this._requestBody:this.isTextRequest()?this.status<g.REQUEST_BODY?"":(this._requestBody=(new TextDecoder).decode(this.request.body),this._requestBody):(this._requestBody="",this._requestBody)}},{key:"hexviewRequestBody",value:function(){var e,t;return null!==this._hexviewRequestBody?this._hexviewRequestBody:this.status<g.REQUEST_BODY?null:(null===(e=this.request)||void 0===e||null===(t=e.body)||void 0===t?void 0:t.byteLength)?(this._hexviewRequestBody=R(this.request.body),this._hexviewRequestBody):null}},{key:"isTextResponse",value:function(){return this.status<g.RESPONSE?null:(null!==this._isTextResponse||(this._isTextResponse=x(this.response)),this._isTextResponse)}},{key:"responseBody",value:function(){var e;return null!==this._responseBody?this._responseBody:this.status<g.RESPONSE?"":this.isTextResponse()?this.status<g.RESPONSE_BODY?"":(this._responseBody=(new TextDecoder).decode(null===(e=this.response)||void 0===e?void 0:e.body),this._responseBody):(this._responseBody="",this._responseBody)}},{key:"previewResponseBody",value:function(){var e,t,s;return this._previewResponseBody?this._previewResponseBody:this.status<g.RESPONSE_BODY?null:(null===(e=this.response)||void 0===e||null===(t=e.body)||void 0===t?void 0:t.byteLength)?(this.response.header["Content-Type"]&&(s=this.response.header["Content-Type"][0]),s?(s.startsWith("image/")?this._previewResponseBody={type:"image",data:S(this.response.body)}:s.includes("application/json")&&(this._previewResponseBody={type:"json",data:this.responseBody()}),this._previewResponseBody):null):null}},{key:"previewRequestBody",value:function(){var e;return this._previewRequestBody?this._previewRequestBody:this.status<g.REQUEST_BODY?null:(null===(e=this.request.body)||void 0===e?void 0:e.byteLength)?(this.isTextRequest()?/json/.test(this.request.header["Content-Type"].join(""))&&(this._previewRequestBody={type:"json",data:this.requestBody()}):this._previewRequestBody={type:"binary",data:this.hexviewRequestBody()},this._previewRequestBody):null}},{key:"hexviewResponseBody",value:function(){var e,t;return null!==this._hexviewResponseBody?this._hexviewResponseBody:this.status<g.RESPONSE_BODY?null:(null===(e=this.response)||void 0===e||null===(t=e.body)||void 0===t?void 0:t.byteLength)?(this._hexviewResponseBody=R(this.response.body),this._hexviewResponseBody):null}},{key:"getConn",value:function(){return this.conn||(this.conn=this.connMgr.get(this.connId)),this.conn}}]),e}();Q.curNo=0;var G=function(){function e(){Object(a.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(c.a)(e,[{key:"showList",value:function(){var e=this.filterText;if(e&&(e=e.trim()),!e)return this.items;if(e.startsWith("/")&&e.endsWith("/")){if(!(e=e.slice(1,e.length-1).trim()))return this.items;try{var t=new RegExp(e);return this.items.filter((function(e){return t.test(e.request.url)}))}catch(s){return this.items}}return this.items.filter((function(t){return t.request.url.includes(e)}))}},{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 s=this;this.filterTimer&&(clearTimeout(this.filterTimer),this.filterTimer=null),this.filterTimer=setTimeout((function(){s.filterText=e,t()}),300)}},{key:"clear",value:function(){this.items=[],this._map=new Map}}]),e}(),Y=function(){function e(){Object(a.a)(this,e),this._map=void 0,this._map=new Map}return Object(c.a)(e,[{key:"get",value:function(e){return this._map.get(e)}},{key:"add",value:function(e,t){this._map.set(e,t)}},{key:"delete",value:function(e){this._map.delete(e)}}]),e}(),F=[1,1,2,2,4,4,8,8,16,16,32,32],W=function(e){Object(l.a)(s,e);var t=Object(d.a)(s);function s(e){var n;return Object(a.a)(this,s),(n=t.call(this,e)).connMgr=void 0,n.flowMgr=void 0,n.ws=void 0,n.wsUnmountClose=void 0,n.tableBottomRef=void 0,n.wsReconnCount=-1,n.connMgr=new Y,n.flowMgr=new G,n.state={flows:n.flowMgr.showList(),flow:null,wsStatus:"close"},n.ws=null,n.wsUnmountClose=!1,n.tableBottomRef=i.a.createRef(),n}return Object(c.a)(s,[{key:"componentDidMount",value:function(){this.initWs()}},{key:"componentWillUnmount",value:function(){this.ws&&(this.wsUnmountClose=!0,this.ws.close(),this.ws=null)}},{key:"initWs",value:function(){var e,t=this;this.ws||(this.setState({wsStatus:"connecting"}),e=new URL(document.URL).host,this.ws=new WebSocket("ws://".concat(e,"/echo")),this.ws.binaryType="arraybuffer",this.ws.onopen=function(){t.wsReconnCount=-1,t.setState({wsStatus:"open"})},this.ws.onerror=function(e){var s;console.error("ERROR:",e),null===(s=t.ws)||void 0===s||s.close()},this.ws.onclose=function(){if(t.setState({wsStatus:"close"}),!t.wsUnmountClose){t.wsReconnCount++,t.ws=null;var e=F[t.wsReconnCount]||F[F.length-1];console.info("will reconnect after ".concat(e," seconds")),setTimeout((function(){t.initWs()}),1e3*e)}},this.ws.onmessage=function(e){var s=function(e){if(e.byteLength<39)return null;var t=new Int8Array(e.slice(0,39));if(2!==t[0])return null;var s=t[1];if(!A.includes(s))return null;var n={type:s,id:(new TextDecoder).decode(e.slice(2,38)),waitIntercept:1===t[38]};if(39===e.byteLength)return n;if(s===g.REQUEST_BODY||s===g.RESPONSE_BODY)return n.content=e.slice(39),n;var i,r=(new TextDecoder).decode(e.slice(39));try{i=JSON.parse(r)}catch(o){return null}return n.content=i,n}(e.data);if(s){if(s.type===g.CONN)t.connMgr.add(s.id,s.content),t.setState({flows:t.state.flows});else if(s.type===g.CONN_CLOSE)t.connMgr.delete(s.id);else if(s.type===g.REQUEST){var n,i=new Q(s,t.connMgr);i.getConn(),t.flowMgr.add(i);var r=!1;(null===(n=t.tableBottomRef)||void 0===n?void 0:n.current)&&function(e){var t=window.innerWidth||document.documentElement.clientWidth,s=window.innerHeight||document.documentElement.clientHeight,n=e.getBoundingClientRect(),i=n.top,r=n.right,o=n.bottom,a=n.left;return i>=0&&a>=0&&r<=t&&o<=s}(t.tableBottomRef.current)&&(r=!0),t.setState({flows:t.flowMgr.showList()},(function(){var e,s;r&&(null===(e=t.tableBottomRef)||void 0===e||null===(s=e.current)||void 0===s||s.scrollIntoView({behavior:"auto"}))}))}else if(s.type===g.REQUEST_BODY){var o=t.flowMgr.get(s.id);if(!o)return;o.addRequestBody(s),t.setState({flows:t.state.flows})}else if(s.type===g.RESPONSE){var a=t.flowMgr.get(s.id);if(!a)return;a.getConn(),a.addResponse(s),t.setState({flows:t.state.flows})}else if(s.type===g.RESPONSE_BODY){var c=t.flowMgr.get(s.id);if(!c||!c.response)return;c.addResponseBody(s),t.setState({flows:t.state.flows})}}else console.error("parse error:",e.data)})}},{key:"render",value:function(){var e=this,t=this.state.flows;return Object(O.jsxs)("div",{className:"main-table-wrap",children:[Object(O.jsxs)("div",{className:"top-control",children:[Object(O.jsx)("div",{children:Object(O.jsx)(p.a,{size:"sm",onClick:function(){e.flowMgr.clear(),e.setState({flows:e.flowMgr.showList(),flow:null})},children:"Clear"})}),Object(O.jsx)("div",{children:Object(O.jsx)(u.a.Control,{size:"sm",placeholder:"Filter",onChange:function(t){var s=t.target.value;e.flowMgr.changeFilterLazy(s,(function(){e.setState({flows:e.flowMgr.showList()})}))}})}),Object(O.jsx)(w,{onSave:function(t){var s=function(e,t){if(e!==M.CHANGE_BREAK_POINT_RULES)throw new Error("invalid message type");var s=(new TextEncoder).encode(JSON.stringify(t)),n=new Uint8Array(2+s.byteLength);return n[0]=1,n[1]=e,n.set(s,2),n}(M.CHANGE_BREAK_POINT_RULES,t);e.ws&&e.ws.send(s)}}),Object(O.jsxs)("span",{children:["status: ",this.state.wsStatus]})]}),Object(O.jsxs)("div",{className:"table-wrap-div",children:[Object(O.jsxs)(h.a,{striped:!0,bordered:!0,size:"sm",style:{tableLayout:"fixed"},children:[Object(O.jsx)("thead",{children:Object(O.jsxs)("tr",{children:[Object(O.jsx)("th",{style:{width:"50px"},children:"No"}),Object(O.jsx)("th",{style:{width:"80px"},children:"Method"}),Object(O.jsx)("th",{style:{width:"200px"},children:"Host"}),Object(O.jsx)("th",{style:{width:"auto"},children:"Path"}),Object(O.jsx)("th",{style:{width:"150px"},children:"Type"}),Object(O.jsx)("th",{style:{width:"80px"},children:"Status"}),Object(O.jsx)("th",{style:{width:"90px"},children:"Size"}),Object(O.jsx)("th",{style:{width:"90px"},children:"Time"})]})}),Object(O.jsx)("tbody",{children:t.map((function(t){var s=t.preview();return Object(O.jsx)(E,{flow:s,isSelected:!(!e.state.flow||e.state.flow.id!==s.id),onShowDetail:function(){e.setState({flow:t})}},s.id)}))})]}),Object(O.jsx)("div",{ref:this.tableBottomRef,id:"hidden-bottom",style:{height:"0px",visibility:"hidden",marginBottom:"1px"}})]}),Object(O.jsx)(z,{flow:this.state.flow,onClose:function(){e.setState({flow:null})},onReRenderFlows:function(){e.setState({flows:e.state.flows})},onMessage:function(t){e.ws&&e.ws.send(t)}})]})}}]),s}(i.a.Component),V=function(e){e&&e instanceof Function&&s.e(3).then(s.bind(null,67)).then((function(t){var s=t.getCLS,n=t.getFID,i=t.getFCP,r=t.getLCP,o=t.getTTFB;s(e),n(e),i(e),r(e),o(e)}))};o.a.render(Object(O.jsx)(i.a.StrictMode,{children:Object(O.jsx)(W,{})}),document.getElementById("root")),V()}},[[65,1,2]]]);
//# sourceMappingURL=main.2abbef8f.chunk.js.map