MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / GetObject

Method GetObject

storage/abs/reader.go:20–103  ·  view source on GitHub ↗

GetObject retrieves an object from Azure cloud

(
	ctx context.Context,
	reqHeader http.Header,
	container, key, _ string,
)

Source from the content-addressed store, hash-verified

18
19// GetObject retrieves an object from Azure cloud
20func (s *Storage) GetObject(
21 ctx context.Context,
22 reqHeader http.Header,
23 container, key, _ string,
24) (*storage.ObjectReader, error) {
25 // If either container or object name is empty, return 404
26 if len(container) == 0 || len(key) == 0 {
27 return storage.NewObjectNotFound(
28 "invalid Azure Storage URL: container name or object key are empty",
29 ), nil
30 }
31
32 // Check if access to the container is allowed
33 if !common.IsBucketAllowed(container, s.config.AllowedBuckets, s.config.DeniedBuckets) {
34 return nil, fmt.Errorf("access to the Azure Storage container %s is denied", container)
35 }
36
37 header := make(http.Header)
38 opts := &blob.DownloadStreamOptions{}
39
40 // Check if this is partial request
41 partial, err := parseRangeHeader(opts, reqHeader)
42 if err != nil {
43 return storage.NewObjectInvalidRange(), nil //nolint:nilerr
44 }
45
46 // Open the object
47 result, err := s.client.DownloadStream(ctx, container, key, opts)
48 if err != nil {
49 //nolint:errorlint
50 azError, ok := err.(*azcore.ResponseError)
51 if !ok || azError.StatusCode < 100 || azError.StatusCode == http.StatusMovedPermanently {
52 return nil, err
53 } else {
54 return storage.NewObjectError(azError.StatusCode, azError.Error()), nil
55 }
56 }
57
58 // Pass through etag and last modified
59 if result.ETag != nil {
60 etag := string(*result.ETag)
61 header.Set(httpheaders.Etag, etag)
62 }
63
64 if result.LastModified != nil {
65 lastModified := result.LastModified.Format(http.TimeFormat)
66 header.Set(httpheaders.LastModified, lastModified)
67 }
68
69 // Break early if response was not modified
70 if !partial && common.IsNotModified(reqHeader, header) {
71 if result.Body != nil {
72 result.Body.Close()
73 }
74
75 return storage.NewObjectNotModified(header), nil
76 }
77

Callers

nothing calls this directly

Calls 14

NewObjectNotFoundFunction · 0.92
IsBucketAllowedFunction · 0.92
NewObjectInvalidRangeFunction · 0.92
NewObjectErrorFunction · 0.92
IsNotModifiedFunction · 0.92
NewObjectNotModifiedFunction · 0.92
NewObjectPartialContentFunction · 0.92
NewObjectOKFunction · 0.92
parseRangeHeaderFunction · 0.85
ErrorfMethod · 0.80
ErrorMethod · 0.65
FormatMethod · 0.65

Tested by

no test coverage detected