From 913febce46d31e25ee128af903a915ec41dd913f Mon Sep 17 00:00:00 2001 From: zanema Date: Wed, 5 Oct 2016 19:29:37 -0500 Subject: [PATCH] return a partial response even when HTTP ultimately fails --- zlib/grabber.go | 4 ++-- ztools/http/response.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/zlib/grabber.go b/zlib/grabber.go index 0873a7a2..fc8f6c01 100644 --- a/zlib/grabber.go +++ b/zlib/grabber.go @@ -286,13 +286,13 @@ func makeHTTPGrabber(config *Config, grabData GrabData) func(string, string, str zlog.Fatalf("Bad HTTP Method: %s. Valid options are: GET, HEAD.", config.HTTP.Method) } + grabData.HTTP.Response = resp + if err != nil { config.ErrorLog.Errorf("Could not connect to remote host %s: %s", fullURL, err.Error()) return err } - grabData.HTTP.Response = resp - if str, err := util.ReadString(resp.Body, config.HTTP.MaxSize*1024); err != nil { return err } else { diff --git a/ztools/http/response.go b/ztools/http/response.go index 0db2c28b..9fbdf239 100644 --- a/ztools/http/response.go +++ b/ztools/http/response.go @@ -167,11 +167,11 @@ func ReadResponse(r *bufio.Reader, req *Request) (resp *Response, err error) { if err == io.EOF { err = io.ErrUnexpectedEOF } - return nil, err + return resp, err } f := strings.SplitN(line, " ", 3) if len(f) < 2 { - return nil, &badStringError{"malformed HTTP response", line} + return resp, &badStringError{"malformed HTTP response", line} } reasonPhrase := "" if len(f) > 2 { @@ -180,20 +180,20 @@ func ReadResponse(r *bufio.Reader, req *Request) (resp *Response, err error) { resp.Status = f[1] + " " + reasonPhrase resp.StatusCode, err = strconv.Atoi(f[1]) if err != nil { - return nil, &badStringError{"malformed HTTP status code", f[1]} + return resp, &badStringError{"malformed HTTP status code", f[1]} } resp.Protocol = *(new(Protocol)) resp.Protocol.Name = f[0] var ok bool if resp.Protocol.Major, resp.Protocol.Minor, ok = ParseHTTPVersion(resp.Protocol.Name); !ok { - return nil, &badStringError{"malformed HTTP version", resp.Protocol.Name} + return resp, &badStringError{"malformed HTTP version", resp.Protocol.Name} } // Parse the response headers. mimeHeader, err := tp.ReadMIMEHeader() if err != nil { - return nil, err + return resp, err } resp.Headers = Header(mimeHeader) @@ -205,7 +205,7 @@ func ReadResponse(r *bufio.Reader, req *Request) (resp *Response, err error) { err = readTransfer(resp, r) if err != nil { - return nil, err + return resp, err } return resp, nil