diff --git a/rustfs/src/admin/handlers.rs b/rustfs/src/admin/handlers.rs index 45cae3e3..bcba70e8 100644 --- a/rustfs/src/admin/handlers.rs +++ b/rustfs/src/admin/handlers.rs @@ -27,6 +27,7 @@ use iam::{auth, get_global_action_cred}; use madmin::metrics::RealtimeMetrics; use madmin::utils::parse_duration; use matchit::Params; +use s3s::header::CONTENT_TYPE; use s3s::stream::{ByteStream, DynByteStream}; use s3s::{ dto::{AssumeRoleOutput, Credentials, Timestamp}, @@ -354,10 +355,13 @@ impl Operation for AccountInfoHandler { policy: bucket_policy, }; - let output = serde_json::to_string(&info) + let data = serde_json::to_vec(&info) .map_err(|_e| S3Error::with_message(S3ErrorCode::InternalError, "parse accountInfo failed"))?; - Ok(S3Response::new((StatusCode::OK, Body::from(output)))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) } } @@ -380,10 +384,13 @@ impl Operation for ServerInfoHandler { let info = get_server_info(true).await; - let output = serde_json::to_string(&info) + let data = serde_json::to_vec(&info) .map_err(|_e| S3Error::with_message(S3ErrorCode::InternalError, "parse serverInfo failed"))?; - Ok(S3Response::new((StatusCode::OK, Body::from(output)))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) } } @@ -413,10 +420,13 @@ impl Operation for StorageInfoHandler { let info = store.storage_info().await; - let output = serde_json::to_string(&info) + let data = serde_json::to_vec(&info) .map_err(|_e| S3Error::with_message(S3ErrorCode::InternalError, "parse accountInfo failed"))?; - Ok(S3Response::new((StatusCode::OK, Body::from(output)))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) } } @@ -436,10 +446,13 @@ impl Operation for DataUsageInfoHandler { s3_error!(InternalError, "load_data_usage_from_backend failed") })?; - let output = serde_json::to_string(&info) + let data = serde_json::to_vec(&info) .map_err(|_e| S3Error::with_message(S3ErrorCode::InternalError, "parse DataUsageInfo failed"))?; - Ok(S3Response::new((StatusCode::OK, Body::from(output)))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) } } @@ -860,10 +873,13 @@ impl Operation for ListPools { pools_status.push(state); } - let output = serde_json::to_string(&pools_status) + let data = serde_json::to_vec(&pools_status) .map_err(|_e| S3Error::with_message(S3ErrorCode::InternalError, "parse accountInfo failed"))?; - Ok(S3Response::new((StatusCode::OK, Body::from(output)))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) } } @@ -927,10 +943,13 @@ impl Operation for StatusPool { let pools_status = store.status(idx).await.map_err(to_s3_error)?; - let output = serde_json::to_string(&pools_status) + let data = serde_json::to_vec(&pools_status) .map_err(|_e| S3Error::with_message(S3ErrorCode::InternalError, "parse accountInfo failed"))?; - Ok(S3Response::new((StatusCode::OK, Body::from(output)))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) } } diff --git a/rustfs/src/admin/handlers/group.rs b/rustfs/src/admin/handlers/group.rs index 53d6fbeb..dee5c515 100644 --- a/rustfs/src/admin/handlers/group.rs +++ b/rustfs/src/admin/handlers/group.rs @@ -1,5 +1,5 @@ use http::StatusCode; -use iam::{error::is_err_no_such_user, get_global_action_cred, Error}; +use iam::{error::is_err_no_such_user, get_global_action_cred}; use madmin::GroupAddRemove; use matchit::Params; use s3s::{s3_error, Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result}; diff --git a/rustfs/src/admin/handlers/service_account.rs b/rustfs/src/admin/handlers/service_account.rs index 6d1c89b3..3b86474f 100644 --- a/rustfs/src/admin/handlers/service_account.rs +++ b/rustfs/src/admin/handlers/service_account.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use http::HeaderMap; use hyper::StatusCode; use iam::{ auth::CredentialsBuilder, @@ -10,7 +11,7 @@ use iam::{ }; use madmin::{AddServiceAccountReq, ListServiceAccountsResp, ServiceAccountInfo}; use matchit::Params; -use s3s::{s3_error, Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result}; +use s3s::{header::CONTENT_TYPE, s3_error, Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result}; use serde_urlencoded::from_bytes; use tracing::{debug, warn}; @@ -277,7 +278,10 @@ impl Operation for ListServiceAccount { let data = serde_json::to_vec(&ListServiceAccountsResp { accounts }) .map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, format!("marshal users err {}", e)))?; - Ok(S3Response::new((StatusCode::OK, Body::from(data)))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) } } diff --git a/rustfs/src/admin/handlers/user.rs b/rustfs/src/admin/handlers/user.rs index f60b8531..7f7afdf0 100644 --- a/rustfs/src/admin/handlers/user.rs +++ b/rustfs/src/admin/handlers/user.rs @@ -1,8 +1,8 @@ -use http::StatusCode; +use http::{HeaderMap, StatusCode}; use iam::get_global_action_cred; use madmin::{AccountStatus, AddOrUpdateUserReq}; use matchit::Params; -use s3s::{s3_error, Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result}; +use s3s::{header::CONTENT_TYPE, s3_error, Body, S3Error, S3ErrorCode, S3Request, S3Response, S3Result}; use serde::Deserialize; use serde_urlencoded::from_bytes; use tracing::warn; @@ -87,7 +87,10 @@ impl Operation for AddUser { .await .map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, format!("create_user err {}", e)))?; - Ok(S3Response::new((StatusCode::OK, Body::empty()))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -128,7 +131,10 @@ impl Operation for SetUserStatus { .await .map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, format!("set_user_status err {}", e)))?; - Ok(S3Response::new((StatusCode::OK, Body::empty()))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -151,7 +157,10 @@ impl Operation for ListUsers { // let body = encrypt_data(input_cred.secret_key.expose().as_bytes(), &data) // .map_err(|e| S3Error::with_message(S3ErrorCode::InvalidArgument, format!("encrypt_data err {}", e)))?; - Ok(S3Response::new((StatusCode::OK, Body::from(data)))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) } } @@ -188,7 +197,10 @@ impl Operation for RemoveUser { .await .map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, format!("delete_user err {}", e)))?; - Ok(S3Response::new((StatusCode::OK, Body::empty()))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -220,6 +232,9 @@ impl Operation for GetUserInfo { let data = serde_json::to_vec(&info) .map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, format!("marshal user err {}", e)))?; - Ok(S3Response::new((StatusCode::OK, Body::from(data)))) + let mut header = HeaderMap::new(); + header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + + Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) } }