52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
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
|
|
}
|