Don't guarantee that (*Response).Body is always non-nil
This commit is contained in:
parent
6b3cf1314b
commit
5332dc6280
3
doc.go
3
doc.go
@ -7,8 +7,11 @@ Get makes a Gemini request:
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// handle error
|
// handle error
|
||||||
}
|
}
|
||||||
|
if resp.Status.Class() == gemini.StatusClassSucess {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
// ...
|
// ...
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
|
||||||
For control over client behavior, create a Client:
|
For control over client behavior, create a Client:
|
||||||
|
|
||||||
|
@ -80,9 +80,9 @@ func main() {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.Status.Class() == gemini.StatusClassSuccess {
|
if resp.Status.Class() == gemini.StatusClassSuccess {
|
||||||
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -2,10 +2,8 @@ package gemini
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,7 +19,6 @@ type Response struct {
|
|||||||
Meta string
|
Meta string
|
||||||
|
|
||||||
// Body contains the response body for successful responses.
|
// Body contains the response body for successful responses.
|
||||||
// Body is guaranteed to be non-nil.
|
|
||||||
Body io.ReadCloser
|
Body io.ReadCloser
|
||||||
|
|
||||||
// Request is the request that was sent to obtain this response.
|
// 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 {
|
if resp.Status.Class() == StatusClassSuccess {
|
||||||
resp.Body = newReadCloserBody(br, rc)
|
resp.Body = newReadCloserBody(br, rc)
|
||||||
} else {
|
|
||||||
resp.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user