From 4b222647b4a97b2f84aa590be071c7481394c225 Mon Sep 17 00:00:00 2001 From: Paul Bonser Date: Fri, 3 Feb 2017 14:06:31 -0600 Subject: [PATCH] Add ability to do a request and just get the raw response bytes back --- goes.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/goes.go b/goes.go index f99976b..5ff3d1c 100644 --- a/goes.go +++ b/goes.go @@ -573,14 +573,28 @@ func (c *Client) AliasExists(alias string) (bool, error) { return resp.Status == 200, err } +func (c *Client) replaceHost(req *http.Request) { + req.URL.Scheme = "http" + req.URL.Host = fmt.Sprintf("%s:%s", c.Host, c.Port) +} + +// DoRaw Does the provided requeset and returns the raw bytes and the status code of the response +func (c *Client) DoRaw(r Requester) ([]byte, uint64, error) { + req, err := r.Request() + if err != nil { + return nil, 0, err + } + c.replaceHost(req) + return c.doRequest(req) +} + // Do runs the request returned by the requestor and returns the parsed response func (c *Client) Do(r Requester) (*Response, error) { req, err := r.Request() if err != nil { return &Response{}, err } - req.URL.Scheme = "http" - req.URL.Host = fmt.Sprintf("%s:%s", c.Host, c.Port) + c.replaceHost(req) body, statusCode, err := c.doRequest(req) esResp := &Response{Status: statusCode}