diff --git a/weed/s3api/s3api_bucket_handlers.go b/weed/s3api/s3api_bucket_handlers.go index 6d998fbe6a..d69b4f857a 100644 --- a/weed/s3api/s3api_bucket_handlers.go +++ b/weed/s3api/s3api_bucket_handlers.go @@ -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 diff --git a/weed/s3api/s3api_bucket_handlers_misc_test.go b/weed/s3api/s3api_bucket_handlers_misc_test.go index 1bd9a2f75c..8649cd5afd 100644 --- a/weed/s3api/s3api_bucket_handlers_misc_test.go +++ b/weed/s3api/s3api_bucket_handlers_misc_test.go @@ -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", "", "") diff --git a/weed/s3api/s3api_xsd_generated.go b/weed/s3api/s3api_xsd_generated.go index aecf95f10c..d8cbb88b03 100644 --- a/weed/s3api/s3api_xsd_generated.go +++ b/weed/s3api/s3api_xsd_generated.go @@ -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"` }