"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
Check server time against local time #654
Nick Craig-Wood8a56a6836a94
diff --git a/fs/http.go b/fs/http.goindex c8f5f20c8..e2b225e2f 100644--- a/fs/http.go+++ b/fs/http.go@@ -143,6 +143,35 @@ func NewTransport(transport *http.Transport, logHeader, logBody bool) *Transport}}+// A map of servers we have checked for time+var checkedHost = make(map[string]struct{}, 1)++// Check the server time is the same as ours, once for each server+func checkServerTime(req *http.Request, resp *http.Response) {+ host := req.URL.Host+ if req.Host != "" {+ host = req.Host+ }+ if _, ok := checkedHost[host]; ok {+ return+ }+ dateString := resp.Header.Get("Date")+ if dateString == "" {+ return+ }+ date, err := http.ParseTime(dateString)+ if err != nil {+ Debug(nil, "Couldn't parse Date: from server %s: %q: %v", host, dateString, err)+ return+ }+ dt := time.Since(date)+ const window = 5 * 60 * time.Second+ if dt > window || dt < -window {+ Log(nil, "Time may be set wrong - time from %q is %v different from this computer", host, dt)+ }+ checkedHost[host] = struct{}{}+}+// RoundTrip implements the RoundTripper interface.func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error) {// Force user agent@@ -169,5 +198,8 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error}Debug(nil, "%s", separatorResp)}+ if err == nil {+ checkServerTime(req, resp)+ }return resp, err}