aboutsummaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2022-11-25 10:59:06 -0700
committerJordan <me@jordan.im>2022-11-25 10:59:06 -0700
commit5eedb519d8beb35d36d409e5e1545f63c0161c49 (patch)
tree47e73e971632685665bbc78e58a1eabb15efb892 /util.go
parent4d69cf999805b9bbe72e9ea5168905546208a345 (diff)
downloadcrane-5eedb519d8beb35d36d409e5e1545f63c0161c49.tar.gz
crane-5eedb519d8beb35d36d409e5e1545f63c0161c49.zip
crane: free descriptors from outbound requests, sci-hub URL
Diffstat (limited to 'util.go')
-rw-r--r--util.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/util.go b/util.go
index 035b519..0fb447f 100644
--- a/util.go
+++ b/util.go
@@ -230,6 +230,7 @@ func getMetaFromDOI(client *http.Client, doi []byte) (*Meta, error) {
if err != nil {
return nil, err
}
+ defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%q: failed to get metadata", u)
@@ -267,6 +268,8 @@ func getPaper(client *http.Client, scihub *url.URL, resource string) (string, er
if err != nil {
return "", err
}
+ defer resp.Body.Close()
+
doc, err := html.Parse(resp.Body)
if err != nil {
return "", err
@@ -303,6 +306,7 @@ func getPaper(client *http.Client, scihub *url.URL, resource string) (string, er
if err != nil {
return "", err
}
+ defer resp.Body.Close()
if resp.Header.Get("content-type") != "application/pdf" {
return "", fmt.Errorf("%q: content-type not application/pdf", refURL.String())
}