summaryrefslogtreecommitdiff
path: root/internal/transport/deliver.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/transport/deliver.go')
-rw-r--r--internal/transport/deliver.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/internal/transport/deliver.go b/internal/transport/deliver.go
index 476152c10..7db3bf338 100644
--- a/internal/transport/deliver.go
+++ b/internal/transport/deliver.go
@@ -19,7 +19,6 @@
package transport
import (
- "bytes"
"context"
"fmt"
"net/http"
@@ -27,6 +26,7 @@ import (
"strings"
"sync"
+ "codeberg.org/gruf/go-byteutil"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
"github.com/superseriousbusiness/gotosocial/internal/config"
)
@@ -49,7 +49,7 @@ func (t *transport) BatchDeliver(ctx context.Context, b []byte, recipients []*ur
wg.Wait()
// receive any buffered errors
- errs := make([]string, 0, len(recipients))
+ errs := make([]string, 0, len(errCh))
outer:
for {
select {
@@ -75,7 +75,11 @@ func (t *transport) Deliver(ctx context.Context, b []byte, to *url.URL) error {
urlStr := to.String()
- req, err := http.NewRequestWithContext(ctx, "POST", urlStr, bytes.NewReader(b))
+ // Use rewindable bytes reader for body.
+ var body byteutil.ReadNopCloser
+ body.Reset(b)
+
+ req, err := http.NewRequestWithContext(ctx, "POST", urlStr, &body)
if err != nil {
return err
}
@@ -92,7 +96,7 @@ func (t *transport) Deliver(ctx context.Context, b []byte, to *url.URL) error {
if code := resp.StatusCode; code != http.StatusOK &&
code != http.StatusCreated && code != http.StatusAccepted {
- return fmt.Errorf("POST request to %s failed (%d): %s", urlStr, resp.StatusCode, resp.Status)
+ return fmt.Errorf("POST request to %s failed: %s", urlStr, resp.Status)
}
return nil