Skip to content

Fetch bucket location and include in HeadBucket response#107

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/extend-headbucket-handler
Draft

Fetch bucket location and include in HeadBucket response#107
Copilot wants to merge 6 commits intomainfrom
copilot/extend-headbucket-handler

Conversation

Copy link

Copilot AI commented Feb 3, 2026

HeadBucket now returns the x-amz-bucket-region header per AWS S3 specification with the actual bucket location fetched from libuplink.

Changes

  • miniogw/gateway.go: Added GetBucketLocation method that uses bucket.GetBucketLocation from libuplink to fetch the actual bucket location
  • api/api.go: Added BucketLocationGetter interface for type assertion to access the gateway layer's GetBucketLocation method
  • api/buckethandlers.go: Updated HeadBucketHandler to fetch actual bucket location and set x-amz-bucket-region header only when location is available. Optimized to use a single call to GetBucketLocation when available instead of two separate calls.
// HeadBucketHandler now makes a single optimized call
// TODO: Add GetBucketLocation to the object layer interface in storj/minio
// instead of using type assertion. This would allow us to make a single call
// instead of two separate calls (GetBucketInfo + GetBucketLocation).
if locationGetter, ok := api.objectAPI.(BucketLocationGetter); ok {
    location, err := locationGetter.GetBucketLocation(ctx, bucketName)
    if err != nil {
        writeErrorResponseHeadersOnly(w, cmd.ToAPIError(ctx, err))
        return
    }
    if location != "" {
        w.Header().Set(xhttp.AmzBucketRegion, location)
    }
} else {
    // Fallback to GetBucketInfo if GetBucketLocation is not available
    if _, err := api.objectAPI.GetBucketInfo(ctx, bucketName); err != nil {
        writeErrorResponseHeadersOnly(w, cmd.ToAPIError(ctx, err))
        return
    }
}

Implementation Details

The implementation is optimized to use a single libuplink call when possible. When the object layer implements BucketLocationGetter, it makes only one call to GetBucketLocation (which validates bucket exists AND returns location). It falls back to GetBucketInfo only when GetBucketLocation is not available. The handler uses type assertion to check if the object layer supports location fetching and only sets the header when a location is successfully retrieved. No default fallback value is used.

A TODO comment has been added to track future work: adding GetBucketLocation to the object layer interface in storj/minio would eliminate the need for type assertion and further streamline the implementation.

Original prompt

there's an ongoing effort to migrate bucket and object handlers from our MinIO fork. while this is happening, let's extend the HeadBucket handler to include the bucket's region in its response. you may need to extract the BucketInfo struct from the MinIO fork and place it in this codebase directly.

references:


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 3, 2026 12:22
- Add x-amz-bucket-region header to HeadBucket response
- Use "us-east-1" as default region (Storj is a global service)
- Add basic test to verify GetBucketInfo works correctly

Co-authored-by: amwolff <30234756+amwolff@users.noreply.github.com>
- Add detailed comments explaining test purpose
- Clarify that HTTP-level testing is done via integration tests
- Document expected HeadBucketHandler behavior

Co-authored-by: amwolff <30234756+amwolff@users.noreply.github.com>
Copilot AI changed the title [WIP] Extend HeadBucket handler to include bucket region Add x-amz-bucket-region header to HeadBucket response Feb 3, 2026
Copilot AI requested a review from amwolff February 3, 2026 12:28
Copy link
Member

@amwolff amwolff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, this won't cut it. we need to modify the implementation of the bucket info-gathering action to fetch information about the bucket along with its region and pass it down here. find out if there's a libuplink method that will allow us to do it in one libuplink call instead of two (bucket info + bucket location).

- Add BucketInfo struct with Location field to api/datatypes.go
- Add GetBucketLocation method to gatewayLayer in miniogw/gateway.go
- Add GetBucketInfoWithLocation helper in api/api.go that fetches both bucket info and location
- Update HeadBucketHandler to use actual bucket location from libuplink
- Falls back to "us-east-1" if location cannot be retrieved
- Remove previous hardcoded implementation

Co-authored-by: amwolff <30234756+amwolff@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 3, 2026

no, this won't cut it. we need to modify the implementation of the bucket info-gathering action to fetch information about the bucket along with its region and pass it down here. find out if there's a...

Done in d743731. The implementation now:

  1. Added GetBucketLocation method to gatewayLayer that calls bucket.GetBucketLocation from libuplink
  2. Created GetBucketInfoWithLocation helper in the API layer that fetches both bucket info and location in separate calls (StatBucket + GetBucketLocation)
  3. Updated HeadBucketHandler to use the actual bucket location from libuplink
  4. Falls back to "us-east-1" if location cannot be retrieved

There's no single libuplink method that returns both bucket info and location, so the implementation uses two separate calls as you suggested to investigate.

Copilot AI changed the title Add x-amz-bucket-region header to HeadBucket response Fetch bucket location and include in HeadBucket response Feb 3, 2026
Copilot AI requested a review from amwolff February 3, 2026 12:46
- Remove unnecessary rename from bucket to bucketObj in GetBucketInfo
- Remove fallback to "us-east-1" when location is not available
- Simplify implementation: call GetBucketInfo and GetBucketLocation separately in HeadBucketHandler
- Remove unused BucketInfo struct and GetBucketInfoWithLocation helper
- Keep BucketLocationGetter interface for type assertion

Co-authored-by: amwolff <30234756+amwolff@users.noreply.github.com>
Copilot AI requested a review from amwolff February 3, 2026 13:25
- Add TODO comment about adding GetBucketLocation to object layer interface in storj/minio
- Make only one call (GetBucketLocation) when objectAPI implements BucketLocationGetter
- Fallback to GetBucketInfo only when GetBucketLocation is not available
- This reduces two sequential calls to one call in the common case

Co-authored-by: amwolff <30234756+amwolff@users.noreply.github.com>
Copilot AI requested a review from amwolff February 3, 2026 17:53
@amwolff
Copy link
Member

amwolff commented Feb 3, 2026

Copy link
Author

Copilot AI commented Feb 3, 2026

@copilot CI is still failing on this (https://build.dev.storj.tools/job/gateway-st/job/PR-107/6/display/redirect)

I've verified the code locally - it builds successfully, all tests pass, and linting checks (go vet, check-imports, check-copyright, check-mod-tidy) all pass. Without access to the full CI logs, I cannot determine the specific failure. Could you share the error message from the CI failure so I can address it?

Copilot AI requested a review from amwolff February 3, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants