mirror of
https://github.com/rclone/rclone.git
synced 2026-10-28 14:28:38 -04:00
The s3 and http backends each carried their own copy of the same CheckRedirect policy. This moves it into lib/rest as StripHeadersOnCrossHostRedirectFn, so that any backend which sends credentials in headers to a host it does not control can use the same policy. It logs at debug level when it strips headers so that a resulting 401 from the redirect target can be diagnosed. A header starting with "*" is matched without canonicalising, as that is how SetHeader and Opts.ExtraHeaders send it. This changes the s3 policy in two edge cases: - It compared the raw URL host string, so a redirect to the same host in different case or with an explicit default port stripped the credentials. It now uses SameHost like the http backend, which treats those as the same host. - The downgrade check compared each hop with the previous one. It now compares with the original request like the other backends, so a chain which starts on plaintext HTTP may return to it. The behaviour tests move to lib/rest. The backend tests which check the policy is wired into each client are kept.