Fix: xml response of get bucket location interface

Signed-off-by: Mofei Zhang <mofei2816@gmail.com>
This commit is contained in:
Mofei Zhang 2020-05-03 20:36:45 +08:00
parent 4f810a945e
commit 9e89d40ddf
No known key found for this signature in database
GPG Key ID: 7C19725C197AE672
2 changed files with 11 additions and 17 deletions

View File

@ -174,22 +174,7 @@ func (o *ObjectNode) listBucketsHandler(w http.ResponseWriter, r *http.Request)
// Get bucket location
// API reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLocation.html
func (o *ObjectNode) getBucketLocation(w http.ResponseWriter, r *http.Request) {
var output = struct {
XMLName xml.Name `xml:"GetBucketLocationOutput"`
LocationConstraint string `xml:"LocationConstraint"`
}{
LocationConstraint: o.region,
}
var marshaled []byte
var err error
if marshaled, err = MarshalXMLEntity(&output); err != nil {
log.LogErrorf("getBucketLocation: marshal result fail: requestID(%v) err(%v)", GetRequestID(r), err)
ServeInternalStaticErrorResponse(w, r)
return
}
if _, err = w.Write(marshaled); err != nil {
log.LogErrorf("getBucketLocation: write response body fail: requestID(%v) err(%v)", GetRequestID(r), err)
}
_, _ = w.Write(o.encodedRegion)
return
}

View File

@ -17,6 +17,7 @@ package objectnode
import (
"context"
"errors"
"fmt"
"net/http"
"regexp"
"strings"
@ -106,6 +107,8 @@ type ObjectNode struct {
signatureIgnoredActions proto.Actions // signature ignored actions
disabledActions proto.Actions // disabled actions
encodedRegion []byte
control common.Control
}
@ -180,6 +183,12 @@ func (o *ObjectNode) loadConfig(cfg *config.Config) (err error) {
return
}
func (o *ObjectNode) updateRegion(region string) {
o.region = region
o.encodedRegion =
[]byte(fmt.Sprintf(fmt.Sprintf("<LocationConstraint>%s</LocationConstraint>", o.region)))
}
func handleStart(s common.Server, cfg *config.Config) (err error) {
o, ok := s.(*ObjectNode)
if !ok {
@ -195,7 +204,7 @@ func handleStart(s common.Server, cfg *config.Config) (err error) {
if ci, err = o.mc.AdminAPI().GetClusterInfo(); err != nil {
return
}
o.region = ci.Cluster
o.updateRegion(ci.Cluster)
log.LogInfof("handleStart: get cluster information: region(%v)", o.region)
// start rest api