Merge pull request #152 from harshavardhana/pr_out_reply_in_xml_from_validate_and_ignore_handlers

This commit is contained in:
Harshavardhana 2015-02-11 22:00:53 -08:00
commit e0b9a2f9ef
3 changed files with 21 additions and 9 deletions

View File

@ -17,6 +17,7 @@ type ErrorResponse struct {
Message string
Resource string
RequestId string
HostId string
}
/// Error codes, non exhaustive list
@ -162,9 +163,12 @@ func getErrorResponse(err Error, resource string) ErrorResponse {
var data = ErrorResponse{}
data.Code = err.Code
data.Message = err.Description
if resource != "" {
data.Resource = resource
}
// TODO implement this in future
data.RequestId = "3LI37"
data.RequestId = "3L137"
data.HostId = "3L137"
return data
}

View File

@ -32,17 +32,23 @@ func validateHandler(conf config.Config, h http.Handler) http.Handler {
func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
accessKey := stripAccessKey(r)
acceptsContentType := getContentType(r)
if accessKey != "" {
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 {
user := h.conf.GetKey(accessKey)
ok, err := signers.ValidateRequest(user, r)
ok, _ := signers.ValidateRequest(user, r)
if ok {
h.handler.ServeHTTP(w, r)
} else {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(err.Error()))
error := errorCodeError(AccessDenied)
errorResponse := getErrorResponse(error, "")
w.WriteHeader(error.HttpStatusCode)
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
}
}
} else {
@ -58,8 +64,12 @@ func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func ignoreUnimplementedResources(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
acceptsContentType := getContentType(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 {
h.ServeHTTP(w, r)
}

View File

@ -21,7 +21,6 @@ import (
"crypto/sha256"
"fmt"
"io"
"log"
"sort"
"strings"
"time"
@ -52,7 +51,6 @@ func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object st
if val, ok := storage.objectdata[key]; ok {
objectBuffer := bytes.NewBuffer(val.data)
written, err := io.Copy(w, objectBuffer)
log.Println("I am here")
return written, err
} else {
return 0, mstorage.ObjectNotFound{Bucket: bucket, Object: object}