From be05b704b0f7f6b03e5e413eaddf90d17d8d8553 Mon Sep 17 00:00:00 2001 From: weisd Date: Fri, 11 Jul 2025 09:40:57 +0800 Subject: [PATCH] feat: add Content-Length headers to admin API responses (#169) --- rustfs/src/admin/handlers/bucket_meta.rs | 1 + rustfs/src/admin/handlers/event.rs | 5 +++++ rustfs/src/admin/handlers/group.rs | 10 +++++++--- rustfs/src/admin/handlers/policys.rs | 12 ++++++++---- rustfs/src/admin/handlers/rebalance.rs | 11 +++++++++-- rustfs/src/admin/handlers/service_account.rs | 5 +++-- rustfs/src/admin/handlers/tier.rs | 18 +++++++++++------- rustfs/src/admin/handlers/user.rs | 6 +++--- 8 files changed, 47 insertions(+), 21 deletions(-) diff --git a/rustfs/src/admin/handlers/bucket_meta.rs b/rustfs/src/admin/handlers/bucket_meta.rs index 074349bc..d05fc570 100644 --- a/rustfs/src/admin/handlers/bucket_meta.rs +++ b/rustfs/src/admin/handlers/bucket_meta.rs @@ -596,6 +596,7 @@ impl Operation for ImportBucketMetadata { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } diff --git a/rustfs/src/admin/handlers/event.rs b/rustfs/src/admin/handlers/event.rs index 2ac2f62d..03c97d49 100644 --- a/rustfs/src/admin/handlers/event.rs +++ b/rustfs/src/admin/handlers/event.rs @@ -19,6 +19,7 @@ use matchit::Params; use rustfs_config::notify::{NOTIFY_MQTT_SUB_SYS, NOTIFY_WEBHOOK_SUB_SYS}; use rustfs_notify::EventName; use rustfs_notify::rules::{BucketNotificationConfig, PatternRules}; +use s3s::header::CONTENT_LENGTH; use s3s::{Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result, header::CONTENT_TYPE, s3_error}; use serde::{Deserialize, Serialize}; use serde_urlencoded::from_bytes; @@ -103,6 +104,7 @@ impl Operation for SetNotificationTarget { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -181,6 +183,7 @@ impl Operation for RemoveNotificationTarget { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -226,6 +229,7 @@ impl Operation for SetBucketNotification { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -289,6 +293,7 @@ impl Operation for RemoveBucketNotification { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } diff --git a/rustfs/src/admin/handlers/group.rs b/rustfs/src/admin/handlers/group.rs index 0fc4f6b5..b2c052fa 100644 --- a/rustfs/src/admin/handlers/group.rs +++ b/rustfs/src/admin/handlers/group.rs @@ -17,7 +17,11 @@ use matchit::Params; use rustfs_ecstore::global::get_global_action_cred; use rustfs_iam::error::{is_err_no_such_group, is_err_no_such_user}; use rustfs_madmin::GroupAddRemove; -use s3s::{Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result, header::CONTENT_TYPE, s3_error}; +use s3s::{ + Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result, + header::{CONTENT_LENGTH, CONTENT_TYPE}, + s3_error, +}; use serde::Deserialize; use serde_urlencoded::from_bytes; use tracing::warn; @@ -129,7 +133,7 @@ impl Operation for SetGroupStatus { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -214,7 +218,7 @@ impl Operation for UpdateGroupMembers { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } diff --git a/rustfs/src/admin/handlers/policys.rs b/rustfs/src/admin/handlers/policys.rs index dd513a1e..2325cd03 100644 --- a/rustfs/src/admin/handlers/policys.rs +++ b/rustfs/src/admin/handlers/policys.rs @@ -19,7 +19,11 @@ use rustfs_ecstore::global::get_global_action_cred; use rustfs_iam::error::is_err_no_such_user; use rustfs_iam::store::MappedPolicy; use rustfs_policy::policy::Policy; -use s3s::{Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result, header::CONTENT_TYPE, s3_error}; +use s3s::{ + Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result, + header::{CONTENT_LENGTH, CONTENT_TYPE}, + s3_error, +}; use serde::Deserialize; use serde_urlencoded::from_bytes; use std::collections::HashMap; @@ -123,7 +127,7 @@ impl Operation for AddCannedPolicy { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -198,7 +202,7 @@ impl Operation for RemoveCannedPolicy { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -284,7 +288,7 @@ impl Operation for SetPolicyForUserOrGroup { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } diff --git a/rustfs/src/admin/handlers/rebalance.rs b/rustfs/src/admin/handlers/rebalance.rs index 1999392d..b3105fa5 100644 --- a/rustfs/src/admin/handlers/rebalance.rs +++ b/rustfs/src/admin/handlers/rebalance.rs @@ -22,7 +22,11 @@ use rustfs_ecstore::{ rebalance::{DiskStat, RebalSaveOpt}, store_api::BucketOptions, }; -use s3s::{Body, S3Request, S3Response, S3Result, header::CONTENT_TYPE, s3_error}; +use s3s::{ + Body, S3Request, S3Response, S3Result, + header::{CONTENT_LENGTH, CONTENT_TYPE}, + s3_error, +}; use serde::{Deserialize, Serialize}; use std::time::Duration; use time::OffsetDateTime; @@ -265,7 +269,10 @@ impl Operation for RebalanceStop { warn!("handle RebalanceStop notification_sys load_rebalance_meta done"); } - Ok(S3Response::new((StatusCode::OK, Body::empty()))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); + Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } diff --git a/rustfs/src/admin/handlers/service_account.rs b/rustfs/src/admin/handlers/service_account.rs index f8f28603..e21926d5 100644 --- a/rustfs/src/admin/handlers/service_account.rs +++ b/rustfs/src/admin/handlers/service_account.rs @@ -28,6 +28,7 @@ use rustfs_madmin::{ use rustfs_policy::policy::action::{Action, AdminAction}; use rustfs_policy::policy::{Args, Policy}; use s3s::S3ErrorCode::InvalidRequest; +use s3s::header::CONTENT_LENGTH; use s3s::{Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result, header::CONTENT_TYPE, s3_error}; use serde::Deserialize; use serde_urlencoded::from_bytes; @@ -306,7 +307,7 @@ impl Operation for UpdateServiceAccount { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -607,7 +608,7 @@ impl Operation for DeleteServiceAccount { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } diff --git a/rustfs/src/admin/handlers/tier.rs b/rustfs/src/admin/handlers/tier.rs index 35c8b4c1..d0c40246 100644 --- a/rustfs/src/admin/handlers/tier.rs +++ b/rustfs/src/admin/handlers/tier.rs @@ -16,7 +16,11 @@ use http::{HeaderMap, StatusCode}; //use iam::get_global_action_cred; use matchit::Params; -use s3s::{Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result, header::CONTENT_TYPE, s3_error}; +use s3s::{ + Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result, + header::{CONTENT_LENGTH, CONTENT_TYPE}, + s3_error, +}; use serde_urlencoded::from_bytes; use time::OffsetDateTime; use tracing::{debug, warn}; @@ -169,7 +173,7 @@ impl Operation for AddTier { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -236,7 +240,7 @@ impl Operation for EditTier { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -332,7 +336,7 @@ impl Operation for RemoveTier { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -366,7 +370,7 @@ impl Operation for VerifyTier { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -457,7 +461,7 @@ impl Operation for ClearTier { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -636,7 +640,7 @@ impl Operation for PostRestoreObject { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } }*/ diff --git a/rustfs/src/admin/handlers/user.rs b/rustfs/src/admin/handlers/user.rs index 64ebcb41..44c8797c 100644 --- a/rustfs/src/admin/handlers/user.rs +++ b/rustfs/src/admin/handlers/user.rs @@ -146,7 +146,7 @@ impl Operation for AddUser { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -193,7 +193,7 @@ impl Operation for SetUserStatus { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -310,7 +310,7 @@ impl Operation for RemoveUser { let mut header = HeaderMap::new(); header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - + header.insert(CONTENT_LENGTH, "0".parse().unwrap()); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } }