working commit

This commit is contained in:
2026-02-27 03:14:24 +02:00
parent 19b173357a
commit 7de22e3816
19 changed files with 827 additions and 150 deletions
+51
View File
@@ -0,0 +1,51 @@
package client
import (
"context"
"fmt"
"net/http"
)
func (cli *Client) GetUpload(ctx context.Context, rawref string) (string, error) {
var err error
var loc string
ref, err := NewReference(rawref)
if err != nil {
return loc, err
}
uri := ref.Upload()
user, pass := ref.Userinfo()
req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, nil)
if err != nil {
return loc, err
}
req.Header.Set("User-Agent", cli.userAgent)
req.Header.Set("Accept", "*/*")
if cli.authenticator != nil {
authHeader, authKey, err := cli.authenticator.MakeHeader(user, pass)
if err != nil {
return loc, err
}
req.Header.Set(authHeader, authKey)
}
resp, err := cli.httpClient.Do(req)
if err != nil {
return loc, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusAccepted {
err := fmt.Errorf("Unxected response code %s", resp.Status)
return loc, err
}
loc = resp.Header.Get("Location")
if loc == "" {
err := fmt.Errorf("Empty location declaration")
return loc, err
}
return loc, err
}