Guarantee that (*Response).Body is non-nil

This commit is contained in:
Adnan Maolood
2020-10-31 23:04:47 -04:00
parent dad8f38bfb
commit 33c1dc435d
2 changed files with 9 additions and 3 deletions

View File

@@ -2,8 +2,10 @@ package gemini
import (
"bufio"
"bytes"
"crypto/tls"
"io"
"io/ioutil"
"strconv"
)
@@ -19,6 +21,7 @@ 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.
@@ -83,6 +86,8 @@ 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
}