mirror of https://github.com/minio/minio.git
Merge pull request #152 from harshavardhana/pr_out_reply_in_xml_from_validate_and_ignore_handlers
This commit is contained in:
commit
e0b9a2f9ef
|
@ -17,6 +17,7 @@ type ErrorResponse struct {
|
||||||
Message string
|
Message string
|
||||||
Resource string
|
Resource string
|
||||||
RequestId string
|
RequestId string
|
||||||
|
HostId string
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Error codes, non exhaustive list
|
/// Error codes, non exhaustive list
|
||||||
|
@ -162,9 +163,12 @@ func getErrorResponse(err Error, resource string) ErrorResponse {
|
||||||
var data = ErrorResponse{}
|
var data = ErrorResponse{}
|
||||||
data.Code = err.Code
|
data.Code = err.Code
|
||||||
data.Message = err.Description
|
data.Message = err.Description
|
||||||
data.Resource = resource
|
if resource != "" {
|
||||||
|
data.Resource = resource
|
||||||
|
}
|
||||||
// TODO implement this in future
|
// TODO implement this in future
|
||||||
data.RequestId = "3LI37"
|
data.RequestId = "3L137"
|
||||||
|
data.HostId = "3L137"
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,17 +32,23 @@ func validateHandler(conf config.Config, h http.Handler) http.Handler {
|
||||||
|
|
||||||
func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
accessKey := stripAccessKey(r)
|
accessKey := stripAccessKey(r)
|
||||||
|
acceptsContentType := getContentType(r)
|
||||||
if accessKey != "" {
|
if accessKey != "" {
|
||||||
if err := h.conf.ReadConfig(); err != nil {
|
if err := h.conf.ReadConfig(); err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
error := errorCodeError(InternalError)
|
||||||
|
errorResponse := getErrorResponse(error, "")
|
||||||
|
w.WriteHeader(error.HttpStatusCode)
|
||||||
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
} else {
|
} else {
|
||||||
user := h.conf.GetKey(accessKey)
|
user := h.conf.GetKey(accessKey)
|
||||||
ok, err := signers.ValidateRequest(user, r)
|
ok, _ := signers.ValidateRequest(user, r)
|
||||||
if ok {
|
if ok {
|
||||||
h.handler.ServeHTTP(w, r)
|
h.handler.ServeHTTP(w, r)
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
error := errorCodeError(AccessDenied)
|
||||||
w.Write([]byte(err.Error()))
|
errorResponse := getErrorResponse(error, "")
|
||||||
|
w.WriteHeader(error.HttpStatusCode)
|
||||||
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -58,8 +64,12 @@ func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func ignoreUnimplementedResources(h http.Handler) http.Handler {
|
func ignoreUnimplementedResources(h http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
acceptsContentType := getContentType(r)
|
||||||
if ignoreUnImplementedObjectResources(r) || ignoreUnImplementedBucketResources(r) {
|
if ignoreUnImplementedObjectResources(r) || ignoreUnImplementedBucketResources(r) {
|
||||||
w.WriteHeader(http.StatusNotImplemented)
|
error := errorCodeError(NotImplemented)
|
||||||
|
errorResponse := getErrorResponse(error, "")
|
||||||
|
w.WriteHeader(error.HttpStatusCode)
|
||||||
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
} else {
|
} else {
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -52,7 +51,6 @@ func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object st
|
||||||
if val, ok := storage.objectdata[key]; ok {
|
if val, ok := storage.objectdata[key]; ok {
|
||||||
objectBuffer := bytes.NewBuffer(val.data)
|
objectBuffer := bytes.NewBuffer(val.data)
|
||||||
written, err := io.Copy(w, objectBuffer)
|
written, err := io.Copy(w, objectBuffer)
|
||||||
log.Println("I am here")
|
|
||||||
return written, err
|
return written, err
|
||||||
} else {
|
} else {
|
||||||
return 0, mstorage.ObjectNotFound{Bucket: bucket, Object: object}
|
return 0, mstorage.ObjectNotFound{Bucket: bucket, Object: object}
|
||||||
|
|
Loading…
Reference in New Issue