Skip to content

Replace manual URL encoding with serde_urlencoded library in Aliyun CDN client#10

Merged
daflyinbed merged 4 commits intoaliyunfrom
copilot/update-cdn-with-serde-urlencoded
Jan 18, 2026
Merged

Replace manual URL encoding with serde_urlencoded library in Aliyun CDN client#10
daflyinbed merged 4 commits intoaliyunfrom
copilot/update-cdn-with-serde-urlencoded

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

Replaced manual form URL encoding implementation in src/aliyun/cdn.rs with the standard serde_urlencoded library for better reliability and maintainability.

Changes

  • Added dependency: serde_urlencoded = "0.7.1" to Cargo.toml
  • Created struct: Added RefreshObjectCachesFormParams struct with proper serde field renaming for type-safe URL encoding
  • Refactored encoding: Replace build_form_urlencoded_body() call with serde_urlencoded::to_string() using the new struct
  • Removed 26 lines: Deleted manual build_form_urlencoded_body() and form_urlencode() helper functions

Before

let mut form_params = BTreeMap::new();
form_params.insert("ObjectPath".to_string(), request.object_path.clone());
// ... manual conditional insertions
let form_body = build_form_urlencoded_body(&form_params);

After

let form_params = RefreshObjectCachesFormParams {
    object_path: request.object_path.clone(),
    object_type: request.object_type.clone(),
    force: request.force,
};

let form_body = serde_urlencoded::to_string(&form_params)
    .context("Failed to encode form parameters")?;

The standard library handles edge cases and encoding rules more robustly than the custom implementation. Using a dedicated struct instead of BTreeMap provides compile-time type safety and clearer intent. The force field maintains its native Option<bool> type for cleaner serialization.

Original prompt

On cdn.rs:270-270, https://github.com/daflyinbed/janus/blob/aliyun/src/aliyun/cdn.rs#L270 改成用serde_urlencoded库来做


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Copilot AI changed the title [WIP] Update cdn.rs to use serde_urlencoded library Replace manual URL encoding with serde_urlencoded library in Aliyun CDN client Jan 17, 2026
Copilot AI requested a review from daflyinbed January 17, 2026 16:36
}

let form_body = build_form_urlencoded_body(&form_params);
let form_body = serde_urlencoded::to_string(&form_params)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot 改成用一个struct而不是btreemap

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Created RefreshObjectCachesFormParams struct with proper serde field renaming for URL encoding. Commit d88d784

…ches

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
object_type: Option<String>,

#[serde(rename = "Force", skip_serializing_if = "Option::is_none")]
force: Option<String>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot 用bool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed force field to Option for cleaner serialization. Commit 7c3016e

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Copilot AI requested a review from daflyinbed January 18, 2026 00:56
@daflyinbed daflyinbed marked this pull request as ready for review January 18, 2026 01:02
@daflyinbed daflyinbed merged commit 9dce098 into aliyun Jan 18, 2026
@daflyinbed daflyinbed deleted the copilot/update-cdn-with-serde-urlencoded branch January 19, 2026 06:17
daflyinbed added a commit that referenced this pull request Jan 19, 2026
…n Aliyun CDN client (#10)

* Initial plan

* Replace manual form encoding with serde_urlencoded library

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>

* Use struct instead of BTreeMap for form parameters in RefreshObjectCaches

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>

* Use bool type for force field instead of String

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants