@ -87,7 +87,7 @@ func setRequestHeaderSizeLimitHandler(h http.Handler) http.Handler {
// of the user-defined metadata to 2 KB.
// of the user-defined metadata to 2 KB.
func ( h requestHeaderSizeLimitHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
func ( h requestHeaderSizeLimitHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
if isHTTPHeaderSizeTooLarge ( r . Header ) {
if isHTTPHeaderSizeTooLarge ( r . Header ) {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrMetadataTooLarge ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrMetadataTooLarge ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
h . Handler . ServeHTTP ( w , r )
h . Handler . ServeHTTP ( w , r )
@ -130,7 +130,7 @@ func filterReservedMetadata(h http.Handler) http.Handler {
// would be treated as metadata.
// would be treated as metadata.
func ( h reservedMetadataHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
func ( h reservedMetadataHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
if containsReservedMetadata ( r . Header ) {
if containsReservedMetadata ( r . Header ) {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrUnsupportedMetadata ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrUnsupportedMetadata ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
h . Handler . ServeHTTP ( w , r )
h . Handler . ServeHTTP ( w , r )
@ -371,14 +371,14 @@ func (h timeValidityHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// All our internal APIs are sensitive towards Date
// All our internal APIs are sensitive towards Date
// header, for all requests where Date header is not
// header, for all requests where Date header is not
// present we will reject such clients.
// present we will reject such clients.
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( errCode ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( errCode ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
// Verify if the request date header is shifted by less than globalMaxSkewTime parameter in the past
// Verify if the request date header is shifted by less than globalMaxSkewTime parameter in the past
// or in the future, reject request otherwise.
// or in the future, reject request otherwise.
curTime := UTCNow ( )
curTime := UTCNow ( )
if curTime . Sub ( amzDate ) > globalMaxSkewTime || amzDate . Sub ( curTime ) > globalMaxSkewTime {
if curTime . Sub ( amzDate ) > globalMaxSkewTime || amzDate . Sub ( curTime ) > globalMaxSkewTime {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrRequestTimeTooSkewed ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrRequestTimeTooSkewed ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
}
}
@ -509,14 +509,14 @@ func (h resourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// If bucketName is present and not objectName check for bucket level resource queries.
// If bucketName is present and not objectName check for bucket level resource queries.
if bucketName != "" && objectName == "" {
if bucketName != "" && objectName == "" {
if ignoreNotImplementedBucketResources ( r ) {
if ignoreNotImplementedBucketResources ( r ) {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrNotImplemented ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrNotImplemented ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
}
}
// If bucketName and objectName are present check for its resource queries.
// If bucketName and objectName are present check for its resource queries.
if bucketName != "" && objectName != "" {
if bucketName != "" && objectName != "" {
if ignoreNotImplementedObjectResources ( r ) {
if ignoreNotImplementedObjectResources ( r ) {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrNotImplemented ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrNotImplemented ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
}
}
@ -589,20 +589,20 @@ func hasMultipleAuth(r *http.Request) bool {
func ( h requestValidityHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
func ( h requestValidityHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
// Check for bad components in URL path.
// Check for bad components in URL path.
if hasBadPathComponent ( r . URL . Path ) {
if hasBadPathComponent ( r . URL . Path ) {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrInvalidResourceName ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrInvalidResourceName ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
// Check for bad components in URL query values.
// Check for bad components in URL query values.
for _ , vv := range r . URL . Query ( ) {
for _ , vv := range r . URL . Query ( ) {
for _ , v := range vv {
for _ , v := range vv {
if hasBadPathComponent ( v ) {
if hasBadPathComponent ( v ) {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrInvalidResourceName ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrInvalidResourceName ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
}
}
}
}
if hasMultipleAuth ( r ) {
if hasMultipleAuth ( r ) {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrInvalidRequest ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrInvalidRequest ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
h . handler . ServeHTTP ( w , r )
h . handler . ServeHTTP ( w , r )
@ -648,10 +648,10 @@ func (f bucketForwardingHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
sr , err := globalDNSConfig . Get ( bucket )
sr , err := globalDNSConfig . Get ( bucket )
if err != nil {
if err != nil {
if err == dns . ErrNoEntriesFound {
if err == dns . ErrNoEntriesFound {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrNoSuchBucket ) ,
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrNoSuchBucket ) ,
r . URL , guessIsBrowserReq ( r ) )
r . URL , guessIsBrowserReq ( r ) )
} else {
} else {
writeErrorResponse ( context . Background ( ) , w , toAPIError ( context . Background ( ) , err ) ,
writeErrorResponse ( r . Context ( ) , w , toAPIError ( r . Context ( ) , err ) ,
r . URL , guessIsBrowserReq ( r ) )
r . URL , guessIsBrowserReq ( r ) )
}
}
return
return
@ -697,9 +697,9 @@ func (f bucketForwardingHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
sr , err := globalDNSConfig . Get ( bucket )
sr , err := globalDNSConfig . Get ( bucket )
if err != nil {
if err != nil {
if err == dns . ErrNoEntriesFound {
if err == dns . ErrNoEntriesFound {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrNoSuchBucket ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrNoSuchBucket ) , r . URL , guessIsBrowserReq ( r ) )
} else {
} else {
writeErrorResponse ( context . Background ( ) , w , toAPIError ( context . Background ( ) , err ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , toAPIError ( r . Context ( ) , err ) , r . URL , guessIsBrowserReq ( r ) )
}
}
return
return
}
}
@ -772,7 +772,7 @@ type criticalErrorHandler struct{ handler http.Handler }
func ( h criticalErrorHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
func ( h criticalErrorHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
defer func ( ) {
defer func ( ) {
if err := recover ( ) ; err == logger . ErrCritical { // handle
if err := recover ( ) ; err == logger . ErrCritical { // handle
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrInternalError ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrInternalError ) , r . URL , guessIsBrowserReq ( r ) )
} else if err != nil {
} else if err != nil {
panic ( err ) // forward other panic calls
panic ( err ) // forward other panic calls
}
}
@ -791,7 +791,7 @@ func (h sseTLSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r . Method == http . MethodHead {
if r . Method == http . MethodHead {
writeErrorResponseHeadersOnly ( w , errorCodes . ToAPIErr ( ErrInsecureSSECustomerRequest ) )
writeErrorResponseHeadersOnly ( w , errorCodes . ToAPIErr ( ErrInsecureSSECustomerRequest ) )
} else {
} else {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrInsecureSSECustomerRequest ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrInsecureSSECustomerRequest ) , r . URL , guessIsBrowserReq ( r ) )
}
}
return
return
}
}