diff --git a/pkg/server/api/generic-handlers.go b/pkg/server/api/generic-handlers.go index e3f81f19a..374b2e3d5 100644 --- a/pkg/server/api/generic-handlers.go +++ b/pkg/server/api/generic-handlers.go @@ -74,7 +74,7 @@ func parseDate(req *http.Request) (time.Time, error) { return time.Time{}, errors.New("invalid request") } -// ValidContentTypeHandler - +// ValidContentTypeHandler to validate Accept type func ValidContentTypeHandler(h http.Handler) http.Handler { return contentTypeHandler{h} } @@ -88,7 +88,7 @@ func (h contentTypeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.handler.ServeHTTP(w, r) } -// TimeValidityHandler - +// TimeValidityHandler to validate parsable time over http header func TimeValidityHandler(h http.Handler) http.Handler { return timeHandler{h} } @@ -119,7 +119,7 @@ func (h timeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // ValidateAuthHeaderHandler - -// validate auth header handler is wrapper handler used for API request validation with authorization header. +// validate auth header handler is wrapper handler used for request validation with authorization header. // Current authorization layer supports S3's standard HMAC based signature request. func ValidateAuthHeaderHandler(h http.Handler) http.Handler { return validateAuthHandler{h} diff --git a/pkg/server/api/headers.go b/pkg/server/api/headers.go index 6d4cb81d3..d7944e8fa 100644 --- a/pkg/server/api/headers.go +++ b/pkg/server/api/headers.go @@ -18,6 +18,7 @@ package api import ( "bytes" + "crypto/rand" "encoding/json" "encoding/xml" "net/http" @@ -33,8 +34,23 @@ type encoder interface { //// helpers +// Static alphaNumeric table used for generating unique request ids +var alphaNumericTable = []byte("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") + +// generateRequestID generate request id +func generateRequestID() []byte { + alpha := make([]byte, 16) + rand.Read(alpha) + for i := 0; i < 16; i++ { + alpha[i] = alphaNumericTable[alpha[i]%byte(len(alphaNumericTable))] + } + return alpha +} + // Write http common headers func setCommonHeaders(w http.ResponseWriter, acceptsType string, contentLength int) { + // set unique request ID for each reply + w.Header().Set("X-Amz-Request-Id", string(generateRequestID())) w.Header().Set("Server", "Minio") w.Header().Set("Accept-Ranges", "bytes") w.Header().Set("Content-Type", acceptsType)