summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-11 13:14:56 -0400
committerdemo <demo@antix1>2026-05-11 13:14:56 -0400
commit240e6cc67beaca71ca87e402c97e825913077d42 (patch)
tree7501af07743f496c7929172aafa50cc3359b7640
parentfa20e7fed19e09028c90e872ad2b0596d8857bb4 (diff)
fix: make fetch return a byte slice instead of an io.Readermaster
There's no way we can use any version of the reader once it's closed (because Fetch exited.)
-rw-r--r--internal/fetch/fetch.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/internal/fetch/fetch.go b/internal/fetch/fetch.go
index f22139d..73ecffa 100644
--- a/internal/fetch/fetch.go
+++ b/internal/fetch/fetch.go
@@ -1,7 +1,6 @@
package fetch
import (
- "bufio"
"fmt"
"io"
"net/http"
@@ -9,10 +8,10 @@ import (
)
// Fetch makes a GET request to rawURL, returning the HTML contents of
-// that webpage in the form of an [io.Reader]. An error is also
-// returned. The parameter timeoutSecs is passed directly to the
-// [http.Client.Timeout] field of the client making the request.
-func Fetch(rawURL string, timeoutSecs int) (io.Reader, error) {
+// that webpage as a []byte. An error is also returned. The parameter
+// timeoutSecs is passed directly to the [http.Client.Timeout] field
+// of the client making the request.
+func Fetch(rawURL string, timeoutSecs int) ([]byte, error) {
client := http.Client{
Timeout: time.Duration(timeoutSecs) * time.Second,
}
@@ -32,5 +31,10 @@ func Fetch(rawURL string, timeoutSecs int) (io.Reader, error) {
return nil, fmt.Errorf("status for %s for %s: %s", http.MethodGet, rawURL, resp.Status)
}
- return bufio.NewReader(resp.Body), nil
+ htmlBytes, err := io.ReadAll(resp.Body)
+ if err != nil {
+ return nil, fmt.Errorf("can't dump response body into byte slice")
+ }
+
+ return htmlBytes, nil
}