(ctx context.Context, objectAPI ObjectLayer, bucket, object string, w http.ResponseWriter, r *http.Request)
| 316 | } |
| 317 | |
| 318 | func (api objectAPIHandlers) getObjectHandler(ctx context.Context, objectAPI ObjectLayer, bucket, object string, w http.ResponseWriter, r *http.Request) { |
| 319 | if crypto.S3.IsRequested(r.Header) || crypto.S3KMS.IsRequested(r.Header) { // If SSE-S3 or SSE-KMS present -> AWS fails with undefined error |
| 320 | writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrBadRequest), r.URL) |
| 321 | return |
| 322 | } |
| 323 | |
| 324 | opts, err := getOpts(ctx, r, bucket, object) |
| 325 | if err != nil { |
| 326 | writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL) |
| 327 | return |
| 328 | } |
| 329 | |
| 330 | // Check for auth type to return S3 compatible error. |
| 331 | // type to return the correct error (NoSuchKey vs AccessDenied) |
| 332 | if s3Error := authenticateRequest(ctx, r, policy.GetObjectAction); s3Error != ErrNone { |
| 333 | if getRequestAuthType(r) == authTypeAnonymous { |
| 334 | // As per "Permission" section in |
| 335 | // https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html |
| 336 | // If the object you request does not exist, |
| 337 | // the error Amazon S3 returns depends on |
| 338 | // whether you also have the s3:ListBucket |
| 339 | // permission. |
| 340 | // * If you have the s3:ListBucket permission |
| 341 | // on the bucket, Amazon S3 will return an |
| 342 | // HTTP status code 404 ("no such key") |
| 343 | // error. |
| 344 | // * if you don’t have the s3:ListBucket |
| 345 | // permission, Amazon S3 will return an HTTP |
| 346 | // status code 403 ("access denied") error.` |
| 347 | if globalPolicySys.IsAllowed(policy.Args{ |
| 348 | Action: policy.ListBucketAction, |
| 349 | BucketName: bucket, |
| 350 | ConditionValues: getConditionValues(r, "", auth.AnonymousCredentials), |
| 351 | IsOwner: false, |
| 352 | }) { |
| 353 | getObjectInfo := objectAPI.GetObjectInfo |
| 354 | if api.CacheAPI() != nil { |
| 355 | getObjectInfo = api.CacheAPI().GetObjectInfo |
| 356 | } |
| 357 | |
| 358 | _, err = getObjectInfo(ctx, bucket, object, opts) |
| 359 | if toAPIError(ctx, err).Code == "NoSuchKey" { |
| 360 | s3Error = ErrNoSuchKey |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | writeErrorResponse(ctx, w, errorCodes.ToAPIErr(s3Error), r.URL) |
| 365 | return |
| 366 | } |
| 367 | |
| 368 | getObjectNInfo := objectAPI.GetObjectNInfo |
| 369 | if api.CacheAPI() != nil { |
| 370 | getObjectNInfo = api.CacheAPI().GetObjectNInfo |
| 371 | } |
| 372 | |
| 373 | // Get request range. |
| 374 | var rs *HTTPRangeSpec |
| 375 | var rangeErr error |
no test coverage detected