Merge pull request #67 from harshavardhana/pr_out_consolidate_reply_headers_simplify_contenttype

master
Harshavardhana 10 years ago
commit 156c35e60a
  1. 59
      pkg/webapi/minioapi/minioapi.go

@ -29,10 +29,8 @@ import (
mstorage "github.com/minio-io/minio/pkg/storage" mstorage "github.com/minio-io/minio/pkg/storage"
) )
type contentType int
const ( const (
xmlType contentType = iota xmlType = iota
jsonType jsonType
) )
@ -135,6 +133,24 @@ func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Reque
} }
} }
func populateHeaders(w http.ResponseWriter, response interface{}, contentType int) []byte {
var bytesBuffer bytes.Buffer
var encoder encoder
if contentType == xmlType {
w.Header().Set("Content-Type", "application/xml")
w.Header().Set("Server", "Minio")
w.Header().Set("Connection", "close")
encoder = xml.NewEncoder(&bytesBuffer)
} else if contentType == jsonType {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Server", "Minio")
w.Header().Set("Connection", "close")
encoder = json.NewEncoder(&bytesBuffer)
}
encoder.Encode(response)
return bytesBuffer.Bytes()
}
func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Request) { func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Request) {
if server.ignoreUnImplementedBucketResources(req) { if server.ignoreUnImplementedBucketResources(req) {
w.WriteHeader(http.StatusNotImplemented) w.WriteHeader(http.StatusNotImplemented)
@ -160,22 +176,7 @@ func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Requ
return return
} }
response := generateBucketsListResult(buckets) response := generateBucketsListResult(buckets)
w.Write(populateHeaders(w, response, contentType))
var bytesBuffer bytes.Buffer
var encoder encoder
if contentType == xmlType {
w.Header().Set("Content-Type", "application/xml")
w.Header().Set("Server", "Minio")
w.Header().Set("Connection", "close")
encoder = xml.NewEncoder(&bytesBuffer)
} else if contentType == jsonType {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Server", "Minio")
w.Header().Set("Connection", "close")
encoder = json.NewEncoder(&bytesBuffer)
}
encoder.Encode(response)
w.Write(bytesBuffer.Bytes())
} }
func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Request) { func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Request) {
@ -205,23 +206,7 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ
return return
} }
response := generateObjectsListResult(bucket, objects, isTruncated) response := generateObjectsListResult(bucket, objects, isTruncated)
w.Write(populateHeaders(w, response, contentType))
var bytesBuffer bytes.Buffer
var encoder encoder
if contentType == xmlType {
w.Header().Set("Content-Type", "application/xml")
w.Header().Set("Server", "Minio")
w.Header().Set("Connection", "close")
encoder = xml.NewEncoder(&bytesBuffer)
} else if contentType == jsonType {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Server", "Minio")
w.Header().Set("Connection", "close")
encoder = json.NewEncoder(&bytesBuffer)
}
encoder.Encode(response)
w.Write(bytesBuffer.Bytes())
} }
func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Request) { func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Request) {
@ -239,6 +224,8 @@ func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Reques
w.Write([]byte(err.Error())) w.Write([]byte(err.Error()))
return return
} }
w.Header().Set("Server", "Minio")
w.Header().Set("Connection", "close")
} }
func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Request) { func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Request) {

Loading…
Cancel
Save