s3api: answer GetBucketLocation with a LocationConstraint document (#13292)

GetBucketLocation wrote the CreateBucket request body
(CreateBucketConfiguration), so clients that check the root element, such
as the AWS Rust SDK, failed with "expected LocationConstraint tag". Reply
with an empty LocationConstraint in the S3 namespace, which is what AWS
sends for us-east-1 buckets.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-12-02 04:10:17 -08:00
1 parent 97cac5f5e5
commit 1f65d9e708
3 files changed
+23 -1

No files matched your search

+1 -1
View File
@@ -1400,7 +1400,7 @@ func (s3a *S3ApiServer) GetBucketLocationHandler(w http.ResponseWriter, r *http.
return
}
writeSuccessResponseXML(w, r, CreateBucketConfiguration{})
writeSuccessResponseXML(w, r, LocationConstraint{})
}
// GetBucketRequestPaymentHandler Get bucket request payment
@@ -3,6 +3,7 @@ package s3api
import (
"context"
"encoding/json"
"encoding/xml"
"fmt"
"io"
"net/http"
@@ -322,6 +323,22 @@ func TestGetBucketLocationInvalidBucketName(t *testing.T) {
}
}
func TestGetBucketLocationReturnsLocationConstraint(t *testing.T) {
s3a := newMiscTestServer(t, "test-bucket")
rec := httptest.NewRecorder()
s3a.GetBucketLocationHandler(rec, newBucketRequest(http.MethodGet, "test-bucket", "location=", ""))
require.Equal(t, http.StatusOK, rec.Code, rec.Body.String())
var got struct {
XMLName xml.Name
Value string `xml:",chardata"`
}
require.NoError(t, xml.Unmarshal(rec.Body.Bytes(), &got), rec.Body.String())
require.Equal(t, xml.Name{Space: "http://s3.amazonaws.com/doc/2006-03-01/", Local: "LocationConstraint"}, got.XMLName, rec.Body.String())
require.Empty(t, got.Value)
}
func TestHandleAutoCreateBucketDisabled(t *testing.T) {
s3a := &S3ApiServer{option: &S3ApiServerOption{}}
req := newBucketRequest(http.MethodPut, "test-bucket", "", "")
+5
View File
@@ -680,6 +680,11 @@ type CreateBucketConfiguration struct {
LocationConstraint string `xml:"LocationConstraint"`
}
type LocationConstraint struct {
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ LocationConstraint"`
Value string `xml:",chardata"`
}
type CreateBucketResponse struct {
CreateBucketReturn CreateBucketResult `xml:"CreateBucketReturn"`
}