import{SecurityDetails}from"./SecurityDetails.js";export class HTTPResponse{constructor(t,e,s){this._contentPromise=null,this._headers={},this._client=t,this._request=e,this._bodyLoadedPromise=new Promise((t=>{this._bodyLoadedPromiseFulfill=t})),this._remoteAddress={ip:s.remoteIPAddress,port:s.remotePort},this._status=s.status,this._statusText=s.statusText,this._url=e.url(),this._fromDiskCache=!!s.fromDiskCache,this._fromServiceWorker=!!s.fromServiceWorker;for(const r of Object.keys(s.headers))this._headers[r.toLowerCase()]=s.headers[r];this._securityDetails=s.securityDetails?new SecurityDetails(s.securityDetails):null}_resolveBody(t){return this._bodyLoadedPromiseFulfill(t)}remoteAddress(){return this._remoteAddress}url(){return this._url}ok(){return 0===this._status||this._status>=200&&this._status<=299}status(){return this._status}statusText(){return this._statusText}headers(){return this._headers}securityDetails(){return this._securityDetails}buffer(){return this._contentPromise||(this._contentPromise=this._bodyLoadedPromise.then((async t=>{if(t)throw t;const e=await this._client.send("Network.getResponseBody",{requestId:this._request._requestId});return Buffer.from(e.body,e.base64Encoded?"base64":"utf8")}))),this._contentPromise}async text(){return(await this.buffer()).toString("utf8")}async json(){const t=await this.text();return JSON.parse(t)}request(){return this._request}fromCache(){return this._fromDiskCache||this._request._fromMemoryCache}fromServiceWorker(){return this._fromServiceWorker}frame(){return this._request.frame()}}