github.com/volts-dev/volts@v0.0.0-20240120094013-5e9c65924106/client/http_response.go (about)

     1  package client
     2  
     3  import (
     4  	"io"
     5  	"net/http"
     6  	"net/url"
     7  
     8  	"github.com/volts-dev/volts/internal/body"
     9  	"github.com/volts-dev/volts/internal/header"
    10  )
    11  
    12  type httpResponse struct {
    13  	response *http.Response
    14  	_header  map[string]string
    15  	body     *body.TBody
    16  
    17  	Status     string // e.g. "200 OK"
    18  	StatusCode int    // e.g. 200
    19  }
    20  
    21  func (self *httpResponse) Body() *body.TBody {
    22  	if self.body.Data.Len() == 0 {
    23  		b, err := io.ReadAll(self.response.Body)
    24  		if err == nil {
    25  			//return nil //, errors.InternalServerError("http.client", err.Error())
    26  			log.Err(err)
    27  		}
    28  		self.body.Data.Write(b)
    29  	}
    30  
    31  	return self.body
    32  }
    33  
    34  func (self *httpResponse) Request() *http.Request {
    35  	return self.response.Request
    36  }
    37  
    38  func (self *httpResponse) Cookies() []*http.Cookie {
    39  	return self.response.Cookies()
    40  }
    41  
    42  func (self *httpResponse) Header() header.Header {
    43  	return header.Header(self.response.Header)
    44  }
    45  
    46  func (self *httpResponse) Location() (*url.URL, error) {
    47  	return self.response.Location()
    48  }
    49  
    50  func (r *httpResponse) Read(out interface{}) error {
    51  
    52  	return nil
    53  }