summaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
Diffstat (limited to 'client.go')
-rw-r--r--client.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/client.go b/client.go
index 0a25110..145b2f8 100644
--- a/client.go
+++ b/client.go
@@ -4,6 +4,7 @@ import (
"crypto/tls"
"errors"
"fmt"
+ "io"
"net/http"
neturl "net/url"
@@ -93,6 +94,20 @@ func (c Client) Fetch(url string) (*Response, error) {
return nil, ExceededMaxRedirects
}
+// Upload sends a request with a body and returns any redirect response.
+func (c Client) Upload(url string, contents *io.LimitedReader) (*Response, error) {
+ u, err := neturl.Parse(url)
+ if err != nil {
+ return nil, err
+ }
+ switch u.Scheme {
+ case "spartan", "http", "https":
+ return c.RoundTrip(&types.Request{URL: u, Meta: contents})
+ default:
+ return nil, fmt.Errorf("upload not supported on %s", u.Scheme)
+ }
+}
+
func getRedirectLocation(proto string, meta any) string {
switch proto {
case "gemini", "spartan":
@@ -103,12 +118,12 @@ func getRedirectLocation(proto string, meta any) string {
return ""
}
-type httpClient struct{
+type httpClient struct {
tp *http.Transport
}
func (hc httpClient) RoundTrip(request *Request) (*Response, error) {
- hreq, err := http.NewRequest("GET", request.URL.String(), nil)
+ hreq, err := http.NewRequest("GET", request.URL.String(), request.Meta.(*io.LimitedReader))
if err != nil {
return nil, err
}