mirror of
https://github.com/versity/versitygw.git
synced 2026-01-08 20:43:07 +00:00
feat: adds Location in CompleteMultipartUpload response
Closes #1714 There is a `Location` field in the `CompleteMultipartUpload` result that represents the newly created object URL. This PR adds this property to the `CompleteMultipartUpload` response, generating it dynamically in either host-style or path-style format, depending on the gateway configuration.
This commit is contained in:
@@ -1631,6 +1631,13 @@ func CompleteMultipartUpload_success(s *S3Conf) error {
|
||||
if getString(res.Key) != obj {
|
||||
return fmt.Errorf("expected object key to be %v, instead got %v", obj, *res.Key)
|
||||
}
|
||||
location := constructObjectLocation(s.endpoint, bucket, obj, s.hostStyle)
|
||||
if res.Location == nil {
|
||||
return fmt.Errorf("expected non nil Location")
|
||||
}
|
||||
if *res.Location != location {
|
||||
return fmt.Errorf("expected Location to be %s, instead got %s", location, *res.Location)
|
||||
}
|
||||
|
||||
ctx, cancel = context.WithTimeout(context.Background(), shortTimeout)
|
||||
resp, err := s3client.HeadObject(ctx, &s3.HeadObjectInput{
|
||||
|
||||
@@ -480,6 +480,28 @@ func listObjects(client *s3.Client, bucket, prefix, delimiter string, maxKeys in
|
||||
return contents, commonPrefixes, nil
|
||||
}
|
||||
|
||||
func constructObjectLocation(endpoint, bucket, object string, hostStyle bool) string {
|
||||
// Normalize endpoint (no trailing slash)
|
||||
endpoint = strings.TrimRight(endpoint, "/")
|
||||
|
||||
if !hostStyle {
|
||||
// Path-style: http://endpoint/bucket/object
|
||||
return fmt.Sprintf("%s/%s/%s", endpoint, bucket, object)
|
||||
}
|
||||
|
||||
// Host-style: http://bucket.endpoint/object
|
||||
u, err := url.Parse(endpoint)
|
||||
if err != nil || u.Host == "" {
|
||||
// Fallback for raw host:port endpoints (e.g. "127.0.0.1:7070")
|
||||
return fmt.Sprintf("http://%s.%s/%s", bucket, endpoint, object)
|
||||
}
|
||||
|
||||
host := u.Host
|
||||
u.Host = fmt.Sprintf("%s.%s", bucket, host)
|
||||
|
||||
return fmt.Sprintf("%s/%s", u.String(), object)
|
||||
}
|
||||
|
||||
func hasObjNames(objs []types.Object, names []string) bool {
|
||||
if len(objs) != len(names) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user