Yansongsongsong commented on code in PR #2256:
URL: 
https://github.com/apache/incubator-opendal/pull/2256#discussion_r1209936283


##########
core/src/services/webdav/backend.rs:
##########
@@ -299,17 +302,81 @@ impl Accessor for WebdavBackend {
     }
 
     async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
-        let resp = self.webdav_get(path, args.range()).await?;
-
-        let status = resp.status();
-
-        match status {
-            StatusCode::OK | StatusCode::PARTIAL_CONTENT => {
-                let meta = parse_into_metadata(path, resp.headers())?;
-                Ok((RpRead::with_metadata(meta), resp.into_body()))
+        let mut remaining_retry_times = 3;
+        // if response indicates that we should redirect
+        // then modify this variable
+        let mut override_endpoint: Option<String> = None;
+        // sometimes path will also changed according to redirect
+        // response
+        let mut override_path: String = path.to_string();
+
+        debug!(
+            "will read with maximum {} times to retry: path={}",
+            &path, remaining_retry_times
+        );
+        while remaining_retry_times > 0 {
+            debug!("remaining retry times: {}", remaining_retry_times);
+            let resp = self
+                .webdav_get(&override_path, args.range(), 
override_endpoint.clone())
+                .await?;
+            let status = resp.status();
+            match status {
+                StatusCode::OK | StatusCode::PARTIAL_CONTENT => {
+                    let meta = parse_into_metadata(path, resp.headers())?;
+                    return Ok((RpRead::with_metadata(meta), resp.into_body()));
+                }
+                StatusCode::FOUND | StatusCode::TEMPORARY_REDIRECT => {
+                    // if server returns redirect HTTP status, then redirect it
+                    let redirected_url = parse_location(resp.headers())?

Review Comment:
   refactored. add one more new function for http client.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to