diff --git a/storage/integration_test.go b/storage/integration_test.go index e8e42ff591c..1b5533c9c9a 100644 --- a/storage/integration_test.go +++ b/storage/integration_test.go @@ -364,6 +364,9 @@ func TestObjects(t *testing.T) { if got, want := rc.ContentType(), "text/plain"; got != want { t.Errorf("ContentType (%q) = %q; want %q", obj, got, want) } + if got, want := rc.CacheControl(), "public, max-age=60"; got != want { + t.Errorf("CacheControl (%q) = %q; want %q", obj, got, want) + } rc.Close() // Check early close. @@ -1448,6 +1451,7 @@ func TestIntegration_RequesterPays(t *testing.T) { func writeObject(ctx context.Context, obj *ObjectHandle, contentType string, contents []byte) error { w := obj.NewWriter(ctx) w.ContentType = contentType + w.CacheControl = "public, max-age=60" if contents != nil { if _, err := w.Write(contents); err != nil { _ = w.Close() diff --git a/storage/reader.go b/storage/reader.go index aa103c17574..c96ca8ae4fd 100644 --- a/storage/reader.go +++ b/storage/reader.go @@ -28,6 +28,7 @@ type Reader struct { body io.ReadCloser remain, size int64 contentType string + cacheControl string checkCRC bool // should we check the CRC? wantCRC uint32 // the CRC32c value the server sent in the header gotCRC uint32 // running crc @@ -72,3 +73,8 @@ func (r *Reader) Remain() int64 { func (r *Reader) ContentType() string { return r.contentType } + +// CacheControl returns the cache control of the object. +func (r *Reader) CacheControl() string { + return r.cacheControl +} diff --git a/storage/storage.go b/storage/storage.go index f9d1b5e2f30..ad2fde4d0e6 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -567,12 +567,13 @@ func (o *ObjectHandle) NewRangeReader(ctx context.Context, offset, length int64) crc, checkCRC = parseCRC32c(res) } return &Reader{ - body: body, - size: size, - remain: remain, - contentType: res.Header.Get("Content-Type"), - wantCRC: crc, - checkCRC: checkCRC, + body: body, + size: size, + remain: remain, + contentType: res.Header.Get("Content-Type"), + cacheControl: res.Header.Get("Cache-Control"), + wantCRC: crc, + checkCRC: checkCRC, }, nil }