@ -87,7 +87,7 @@ func setRequestHeaderSizeLimitHandler(h http.Handler) http.Handler {
// of the user-defined metadata to 2 KB.
func ( h requestHeaderSizeLimitHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
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
}
h . Handler . ServeHTTP ( w , r )
@ -130,7 +130,7 @@ func filterReservedMetadata(h http.Handler) http.Handler {
// would be treated as metadata.
func ( h reservedMetadataHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
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
}
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
// header, for all requests where Date header is not
// 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
}
// Verify if the request date header is shifted by less than globalMaxSkewTime parameter in the past
// or in the future, reject request otherwise.
curTime := UTCNow ( )
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
}
}
@ -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 != "" && objectName == "" {
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
}
}
// If bucketName and objectName are present check for its resource queries.
if bucketName != "" && objectName != "" {
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
}
}
@ -589,20 +589,20 @@ func hasMultipleAuth(r *http.Request) bool {
func ( h requestValidityHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
// Check for bad components in 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
}
// Check for bad components in URL query values.
for _ , vv := range r . URL . Query ( ) {
for _ , v := range vv {
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
}
}
}
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
}
h . handler . ServeHTTP ( w , r )
@ -648,10 +648,10 @@ func (f bucketForwardingHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
sr , err := globalDNSConfig . Get ( bucket )
if err != nil {
if err == dns . ErrNoEntriesFound {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrNoSuchBucket ) ,
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrNoSuchBucket ) ,
r . URL , guessIsBrowserReq ( r ) )
} else {
writeErrorResponse ( context . Background ( ) , w , toAPIError ( context . Background ( ) , err ) ,
writeErrorResponse ( r . Context ( ) , w , toAPIError ( r . Context ( ) , err ) ,
r . URL , guessIsBrowserReq ( r ) )
}
return
@ -697,9 +697,9 @@ func (f bucketForwardingHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
sr , err := globalDNSConfig . Get ( bucket )
if err != nil {
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 {
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
}
@ -772,7 +772,7 @@ type criticalErrorHandler struct{ handler http.Handler }
func ( h criticalErrorHandler ) ServeHTTP ( w http . ResponseWriter , r * http . Request ) {
defer func ( ) {
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 {
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 {
writeErrorResponseHeadersOnly ( w , errorCodes . ToAPIErr ( ErrInsecureSSECustomerRequest ) )
} else {
writeErrorResponse ( context . Background ( ) , w , errorCodes . ToAPIErr ( ErrInsecureSSECustomerRequest ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( r . Context ( ) , w , errorCodes . ToAPIErr ( ErrInsecureSSECustomerRequest ) , r . URL , guessIsBrowserReq ( r ) )
}
return
}