committed by
Sacha Al Himdani
parent
3c7a27b7ff
commit
b1cc17ab26
@@ -170,6 +170,7 @@ func TestTrustCenter_LogoFileDownloadURL(t *testing.T) {
|
|||||||
// redirect) with cache headers, so the stable URL is CDN/browser cacheable.
|
// redirect) with cache headers, so the stable URL is CDN/browser cacheable.
|
||||||
resp, err := http.Get(downloadURL)
|
resp, err := http.Get(downloadURL)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
defer func() { _ = resp.Body.Close() }()
|
defer func() { _ = resp.Body.Close() }()
|
||||||
|
|
||||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
@@ -199,6 +200,7 @@ func TestTrustCenter_LogoFileDownloadURL(t *testing.T) {
|
|||||||
|
|
||||||
revalidateResp, err := http.DefaultClient.Do(revalidateReq)
|
revalidateResp, err := http.DefaultClient.Do(revalidateReq)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
defer func() { _ = revalidateResp.Body.Close() }()
|
defer func() { _ = revalidateResp.Body.Close() }()
|
||||||
|
|
||||||
assert.Equal(t, http.StatusNotModified, revalidateResp.StatusCode)
|
assert.Equal(t, http.StatusNotModified, revalidateResp.StatusCode)
|
||||||
@@ -214,6 +216,7 @@ func TestTrustCenter_LogoFileDownloadURL(t *testing.T) {
|
|||||||
|
|
||||||
sinceResp, err := http.DefaultClient.Do(sinceReq)
|
sinceResp, err := http.DefaultClient.Do(sinceReq)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
defer func() { _ = sinceResp.Body.Close() }()
|
defer func() { _ = sinceResp.Body.Close() }()
|
||||||
|
|
||||||
assert.Equal(t, http.StatusNotModified, sinceResp.StatusCode)
|
assert.Equal(t, http.StatusNotModified, sinceResp.StatusCode)
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ import (
|
|||||||
"go.probo.inc/probo/pkg/coredata"
|
"go.probo.inc/probo/pkg/coredata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileObject carries a streamed S3 object body plus the metadata needed to set
|
|
||||||
// HTTP response headers. NotModified is set when the caller's conditional
|
|
||||||
// request matched the current object, in which case Body is nil.
|
|
||||||
type FileObject struct {
|
type FileObject struct {
|
||||||
Body io.ReadCloser
|
Body io.ReadCloser
|
||||||
ContentType string
|
ContentType string
|
||||||
@@ -42,9 +39,6 @@ type FileObject struct {
|
|||||||
NotModified bool
|
NotModified bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileConditions carries HTTP conditional-request values forwarded to S3 so it
|
|
||||||
// can answer with 304 Not Modified without transferring the body. Zero values
|
|
||||||
// are omitted.
|
|
||||||
type FileConditions struct {
|
type FileConditions struct {
|
||||||
IfNoneMatch string
|
IfNoneMatch string
|
||||||
IfModifiedSince time.Time
|
IfModifiedSince time.Time
|
||||||
@@ -100,10 +94,6 @@ func (s *Service) GetFileBytes(
|
|||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenFile streams an object from S3 without buffering it in memory. Conditional
|
|
||||||
// request values in conds are forwarded to S3; a 304 Not Modified response is
|
|
||||||
// surfaced as a FileObject with NotModified set (and a nil Body). The caller
|
|
||||||
// owns closing Body.
|
|
||||||
func (s *Service) OpenFile(
|
func (s *Service) OpenFile(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
file *coredata.File,
|
file *coredata.File,
|
||||||
@@ -116,6 +106,7 @@ func (s *Service) OpenFile(
|
|||||||
if conds.IfNoneMatch != "" {
|
if conds.IfNoneMatch != "" {
|
||||||
input.IfNoneMatch = &conds.IfNoneMatch
|
input.IfNoneMatch = &conds.IfNoneMatch
|
||||||
}
|
}
|
||||||
|
|
||||||
if !conds.IfModifiedSince.IsZero() {
|
if !conds.IfModifiedSince.IsZero() {
|
||||||
input.IfModifiedSince = &conds.IfModifiedSince
|
input.IfModifiedSince = &conds.IfModifiedSince
|
||||||
}
|
}
|
||||||
@@ -140,6 +131,7 @@ func (s *Service) OpenFile(
|
|||||||
if result.ETag != nil {
|
if result.ETag != nil {
|
||||||
obj.ETag = *result.ETag
|
obj.ETag = *result.ETag
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.LastModified != nil {
|
if result.LastModified != nil {
|
||||||
obj.LastModified = *result.LastModified
|
obj.LastModified = *result.LastModified
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user