Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

backend/http: parse get responses when no_head is set

Arnie97cafce9618521
diff --git a/backend/http/http.go b/backend/http/http.go
index 3e6e83155..59a23916e 100644
--- a/backend/http/http.go
+++ b/backend/http/http.go
@@ -305,7 +305,7 @@ func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) {
fs: f,
remote: remote,
}
- err := o.stat(ctx)
+ err := o.head(ctx)
if err != nil {
return nil, err
}
@@ -500,7 +500,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
fs: f,
remote: remote,
}
- switch err := file.stat(ctx); err {
+ switch err := file.head(ctx); err {
case nil:
add(file)
case fs.ErrorNotAFile:
@@ -579,8 +579,8 @@ func (o *Object) url() string {
return o.fs.url(o.remote)
}
-// stat updates the info field in the Object
-func (o *Object) stat(ctx context.Context) error {
+// head sends a HEAD request to update info fields in the Object
+func (o *Object) head(ctx context.Context) error {
if o.fs.opt.NoHead {
o.size = -1
o.modTime = timeUnset
@@ -601,6 +601,11 @@ func (o *Object) stat(ctx context.Context) error {
if err != nil {
return fmt.Errorf("failed to stat: %w", err)
}
+ return o.stat(ctx, res)
+}
+
+// stat updates info fields in the Object according to HTTP response headers
+func (o *Object) stat(ctx context.Context, res *http.Response) error {
t, err := http.ParseTime(res.Header.Get("Last-Modified"))
if err != nil {
t = timeUnset
@@ -653,6 +658,12 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
if err != nil {
return nil, fmt.Errorf("Open failed: %w", err)
}
+
+ if o.fs.opt.NoHead {
+ if err = o.stat(ctx, res); err != nil {
+ return nil, fmt.Errorf("Stat failed: %w", err)
+ }
+ }
return res.Body, nil
}