Xuanwo commented on code in PR #5500:
URL: https://github.com/apache/opendal/pull/5500#discussion_r1901753213


##########
core/src/raw/http_util/body.rs:
##########
@@ -39,7 +39,7 @@ pub struct HttpBody {
 
 /// # Safety
 ///
-/// HttpBody is send on non wasm32 targets.
+/// HttpBody is sent on non wasm32 targets.

Review Comment:
   "send" here is not a typo. You can change it to `Send` with "`" if you find 
it confusing.



##########
core/src/raw/chrono_util.rs:
##########
@@ -62,3 +62,10 @@ pub fn parse_datetime_from_from_timestamp(s: i64) -> 
Result<DateTime<Utc>> {
 
     Ok(st.into())
 }
+
+/// format datetime to rfc1123
+///
+/// for example: `Sun, 06 Nov 1994 08:49:37 GMT`
+pub fn to_rfc_1123(s: DateTime<Utc>) -> String {

Review Comment:
   I suggest to use `format_datetime_into_http_date` as API name.
   
   Besides, how about adding a test case for this?



##########
core/src/types/capability.rs:
##########
@@ -115,6 +115,10 @@ pub struct Capability {
     pub read_with_override_content_type: bool,
     /// Indicates if versions read operations are supported.
     pub read_with_version: bool,
+    /// Indicates if conditional read operations using If-Modified-Since are 
supported.
+    pub read_with_if_modified_since: bool,

Review Comment:
   The same.



##########
core/tests/behavior/async_read.rs:
##########
@@ -270,6 +274,74 @@ pub async fn test_reader_with_if_none_match(op: Operator) 
-> anyhow::Result<()>
     Ok(())
 }
 
+/// Reader with if_modified_since should match, otherwise, a ConditionNotMatch 
error will be returned.
+pub async fn test_reader_with_if_modified_since(op: Operator) -> 
anyhow::Result<()> {
+    if !op.info().full_capability().read_with_if_modified_since {
+        return Ok(());
+    }
+
+    let (path, content, _) = TEST_FIXTURE.new_file(op.clone());
+
+    op.write(&path, content.clone())
+        .await
+        .expect("write must succeed");
+
+    let one_hour_ago_check = chrono::Utc::now() - 
chrono::Duration::seconds(3600);
+    let reader = op
+        .reader_with(&path)
+        .if_modified_since(one_hour_ago_check)
+        .await?;
+    let bs = reader.read(..).await?.to_bytes();
+    assert_eq!(bs, content);
+
+    sleep(Duration::from_secs(3)).await;

Review Comment:
   It's better to remove this sleep.



##########
core/src/services/s3/backend.rs:
##########
@@ -948,6 +948,8 @@ impl Access for S3Backend {
                 read_with_override_content_disposition: true,
                 read_with_override_content_type: true,
                 read_with_version: self.core.enable_versioning,
+                read_with_if_modified_since: true,

Review Comment:
   Please arrange them in the correct order.



##########
core/src/raw/ops.rs:
##########
@@ -419,6 +421,28 @@ impl OpRead {
     pub fn executor(&self) -> Option<&Executor> {
         self.executor.as_ref()
     }
+
+    /// Set the If-Modified-Since of the option
+    pub fn with_if_modified_since(mut self, if_modified_since: DateTime<Utc>) 
-> Self {

Review Comment:
   The same, please place besides `if_none_match`



##########
core/src/raw/ops.rs:
##########
@@ -419,6 +421,28 @@ impl OpRead {
     pub fn executor(&self) -> Option<&Executor> {
         self.executor.as_ref()
     }
+
+    /// Set the If-Modified-Since of the option
+    pub fn with_if_modified_since(mut self, if_modified_since: DateTime<Utc>) 
-> Self {
+        self.if_modified_since = Some(if_modified_since);
+        self
+    }
+
+    /// Get If-Modified-Since from option
+    pub fn if_modified_since(&self) -> Option<DateTime<Utc>> {
+        self.if_modified_since
+    }
+
+    /// Set the If-Unmodified-Since of the option
+    pub fn with_if_unmodified_since(mut self, if_unmodified_since: 
DateTime<Utc>) -> Self {

Review Comment:
   Using `v: DateTime<Utc>` is clear enough; I don't think the full name is 
necessary here.



##########
core/src/raw/ops.rs:
##########
@@ -304,6 +304,8 @@ pub struct OpRead {
     override_content_disposition: Option<String>,
     version: Option<String>,
     executor: Option<Executor>,
+    if_modified_since: Option<DateTime<Utc>>,

Review Comment:
   Please include those fields under `if_none_match`.



##########
core/tests/behavior/async_read.rs:
##########
@@ -270,6 +274,74 @@ pub async fn test_reader_with_if_none_match(op: Operator) 
-> anyhow::Result<()>
     Ok(())
 }
 
+/// Reader with if_modified_since should match, otherwise, a ConditionNotMatch 
error will be returned.
+pub async fn test_reader_with_if_modified_since(op: Operator) -> 
anyhow::Result<()> {
+    if !op.info().full_capability().read_with_if_modified_since {
+        return Ok(());
+    }
+
+    let (path, content, _) = TEST_FIXTURE.new_file(op.clone());
+
+    op.write(&path, content.clone())
+        .await
+        .expect("write must succeed");
+
+    let one_hour_ago_check = chrono::Utc::now() - 
chrono::Duration::seconds(3600);
+    let reader = op
+        .reader_with(&path)
+        .if_modified_since(one_hour_ago_check)
+        .await?;
+    let bs = reader.read(..).await?.to_bytes();
+    assert_eq!(bs, content);
+
+    sleep(Duration::from_secs(3)).await;
+
+    let one_second_ago_check = chrono::Utc::now() - 
chrono::Duration::seconds(1);

Review Comment:
   How about using `chrono::Utc::now() + chrono::Duration::seconds(10)`? Also, 
the name `one_second_ago_check` is incorrect. I recommend avoiding lengthy 
names; a simple `since` should suffice.



-- 
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