diff --git a/doc.go b/doc.go index 944adbb..ea988ef 100644 --- a/doc.go +++ b/doc.go @@ -7,7 +7,10 @@ Get makes a Gemini request: if err != nil { // handle error } - defer resp.Body.Close() + if resp.Status.Class() == gemini.StatusClassSucess { + defer resp.Body.Close() + // ... + } // ... For control over client behavior, create a Client: diff --git a/examples/client.go b/examples/client.go index 9f5efae..012e6df 100644 --- a/examples/client.go +++ b/examples/client.go @@ -80,9 +80,9 @@ func main() { fmt.Println(err) os.Exit(1) } - defer resp.Body.Close() if resp.Status.Class() == gemini.StatusClassSuccess { + defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) diff --git a/response.go b/response.go index 89d4d5c..8f24419 100644 --- a/response.go +++ b/response.go @@ -2,10 +2,8 @@ package gemini import ( "bufio" - "bytes" "crypto/tls" "io" - "io/ioutil" "strconv" ) @@ -21,7 +19,6 @@ type Response struct { Meta string // Body contains the response body for successful responses. - // Body is guaranteed to be non-nil. Body io.ReadCloser // Request is the request that was sent to obtain this response. @@ -86,8 +83,6 @@ func (resp *Response) read(rc io.ReadCloser) error { if resp.Status.Class() == StatusClassSuccess { resp.Body = newReadCloserBody(br, rc) - } else { - resp.Body = ioutil.NopCloser(bytes.NewReader([]byte{})) } return nil }