This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 5384936b0 feat(services/dropbox): read support range (#2848)
5384936b0 is described below

commit 5384936b07d97689770b475c8b146b794042aa1e
Author: Suyan <[email protected]>
AuthorDate: Tue Aug 15 10:40:13 2023 +0800

    feat(services/dropbox): read support range (#2848)
    
    * feat(services/dropbox): read support range
    
    Signed-off-by: suyanhanx <[email protected]>
    
    * fix core debug display
    
    Signed-off-by: suyanhanx <[email protected]>
    
    * fix parse http status 206
    
    Signed-off-by: suyanhanx <[email protected]>
    
    * merge use crate::raw
    
    Signed-off-by: suyanhanx <[email protected]>
    
    ---------
    
    Signed-off-by: suyanhanx <[email protected]>
---
 core/src/services/dropbox/backend.rs |  7 ++++---
 core/src/services/dropbox/core.rs    | 34 +++++++++++++++++++---------------
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/core/src/services/dropbox/backend.rs 
b/core/src/services/dropbox/backend.rs
index 5567285d0..642d22801 100644
--- a/core/src/services/dropbox/backend.rs
+++ b/core/src/services/dropbox/backend.rs
@@ -63,6 +63,7 @@ impl Accessor for DropboxBackend {
                 stat: true,
 
                 read: true,
+                read_with_range: true,
 
                 write: true,
 
@@ -93,11 +94,11 @@ impl Accessor for DropboxBackend {
         }
     }
 
-    async fn read(&self, path: &str, _args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
-        let resp = self.core.dropbox_get(path).await?;
+    async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
+        let resp = self.core.dropbox_get(path, args).await?;
         let status = resp.status();
         match status {
-            StatusCode::OK => {
+            StatusCode::OK | StatusCode::PARTIAL_CONTENT => {
                 let meta = parse_into_metadata(path, resp.headers())?;
                 Ok((RpRead::with_metadata(meta), resp.into_body()))
             }
diff --git a/core/src/services/dropbox/core.rs 
b/core/src/services/dropbox/core.rs
index 4f5be56bf..a334c919e 100644
--- a/core/src/services/dropbox/core.rs
+++ b/core/src/services/dropbox/core.rs
@@ -33,16 +33,7 @@ use serde::Deserialize;
 use serde::Serialize;
 use tokio::sync::Mutex;
 
-use crate::raw::build_rooted_abs_path;
-use crate::raw::new_json_deserialize_error;
-use crate::raw::new_json_serialize_error;
-use crate::raw::new_request_build_error;
-use crate::raw::AsyncBody;
-use crate::raw::BatchedReply;
-use crate::raw::HttpClient;
-use crate::raw::IncomingAsyncBody;
-use crate::raw::RpBatch;
-use crate::raw::RpDelete;
+use crate::raw::*;
 use crate::services::dropbox::backend::DropboxDeleteBatchResponse;
 use crate::services::dropbox::backend::DropboxDeleteBatchResponseEntry;
 use crate::services::dropbox::error::parse_error;
@@ -58,8 +49,9 @@ pub struct DropboxCore {
 
 impl Debug for DropboxCore {
     fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
-        let mut de = f.debug_struct("DropboxCore");
-        de.finish()
+        f.debug_struct("DropboxCore")
+            .field("root", &self.root)
+            .finish()
     }
 }
 
@@ -71,16 +63,28 @@ impl DropboxCore {
         path.trim_end_matches('/').to_string()
     }
 
-    pub async fn dropbox_get(&self, path: &str) -> 
Result<Response<IncomingAsyncBody>> {
+    pub async fn dropbox_get(
+        &self,
+        path: &str,
+        args: OpRead,
+    ) -> Result<Response<IncomingAsyncBody>> {
         let url: String = 
"https://content.dropboxapi.com/2/files/download".to_string();
         let download_args = DropboxDownloadArgs {
             path: build_rooted_abs_path(&self.root, path),
         };
         let request_payload =
             
serde_json::to_string(&download_args).map_err(new_json_serialize_error)?;
-        let mut request = Request::post(&url)
+
+        let mut req = Request::post(&url)
             .header("Dropbox-API-Arg", request_payload)
-            .header(CONTENT_LENGTH, 0)
+            .header(CONTENT_LENGTH, 0);
+
+        let range = args.range();
+        if !range.is_full() {
+            req = req.header(header::RANGE, range.to_header());
+        }
+
+        let mut request = req
             .body(AsyncBody::Empty)
             .map_err(new_request_build_error)?;
 

Reply via email to