Update deps

This commit is contained in:
eleksir
2025-02-09 15:15:23 +03:00
parent 07430d87ed
commit 6cebe40018
206 changed files with 6461 additions and 3066 deletions

View File

@@ -2,7 +2,9 @@ package requests
import (
"compress/gzip"
"fmt"
"io"
"mime/multipart"
"net/http/httptest"
)
@@ -43,3 +45,33 @@ func TestServerConfig(s *httptest.Server) Config {
Client(s.Client())
}
}
// BodyMultipart returns a Config
// that uses a multipart.Writer for the request body.
// If boundary is "", a multipart boundary is chosen at random.
// The content type of the request is set to multipart/form-data
// with the correct boundary.
// The multipart.Writer is automatically closed if the callback succeeds.
func BodyMultipart(boundary string, h func(multi *multipart.Writer) error) Config {
return func(rb *Builder) {
if boundary == "" {
multi := multipart.NewWriter(nil)
boundary = multi.Boundary()
}
rb.
ContentType("multipart/form-data; boundary=" + boundary).
BodyWriter(func(w io.Writer) error {
multi := multipart.NewWriter(w)
if err := multi.SetBoundary(boundary); err != nil {
return fmt.Errorf("setting boundary: %w", err)
}
if err := h(multi); err != nil {
return err
}
if err := multi.Close(); err != nil {
return fmt.Errorf("closing multipart writer: %w", err)
}
return nil
})
}
}