K2V #293

Merged
lx merged 68 commits from k2v into main 2022-05-10 11:16:58 +00:00
2 changed files with 19 additions and 10 deletions
Showing only changes of commit e9e76f6fc5 - Show all commits

View file

@ -91,16 +91,32 @@ impl<'a> RequestBuilder<'a> {
self self
} }
pub fn query_param<T, U>(&mut self, param: T, value: Option<U>) -> &mut Self
where T: ToString, U: ToString, {
self.query_params.insert(param.to_string(), value.as_ref().map(ToString::to_string));
self
}
pub fn signed_headers(&mut self, signed_headers: HashMap<String, String>) -> &mut Self { pub fn signed_headers(&mut self, signed_headers: HashMap<String, String>) -> &mut Self {
self.signed_headers = signed_headers; self.signed_headers = signed_headers;
self self
} }
pub fn signed_header(&mut self, name: impl ToString, value: impl ToString) -> &mut Self {
self.signed_headers.insert(name.to_string(), value.to_string());
self
}
pub fn unsigned_headers(&mut self, unsigned_headers: HashMap<String, String>) -> &mut Self { pub fn unsigned_headers(&mut self, unsigned_headers: HashMap<String, String>) -> &mut Self {
self.unsigned_headers = unsigned_headers; self.unsigned_headers = unsigned_headers;
self self
} }
pub fn unsigned_header(&mut self, name: impl ToString, value: impl ToString) -> &mut Self {
self.unsigned_headers.insert(name.to_string(), value.to_string());
self
}
pub fn body(&mut self, body: Vec<u8>) -> &mut Self { pub fn body(&mut self, body: Vec<u8>) -> &mut Self {
self.body = body; self.body = body;
self self

View file

@ -1,4 +1,3 @@
use std::collections::HashMap;
use crate::common; use crate::common;
use common::custom_requester::BodySignature; use common::custom_requester::BodySignature;
@ -9,14 +8,11 @@ async fn test_simple() {
let ctx = common::context(); let ctx = common::context();
let bucket = ctx.create_bucket("test-k2v-simple"); let bucket = ctx.create_bucket("test-k2v-simple");
let mut query_params = HashMap::new();
query_params.insert("sort_key".to_string(), Some("test1".to_string()));
let res = ctx.k2v.request let res = ctx.k2v.request
.builder(bucket.clone()) .builder(bucket.clone())
.method(Method::PUT) .method(Method::PUT)
.path("root".into()) .path("root".into())
.query_params(query_params.clone()) .query_param("sort_key", Some("test1"))
.body(b"Hello, world!".to_vec()) .body(b"Hello, world!".to_vec())
.body_signature(BodySignature::Classic) .body_signature(BodySignature::Classic)
.send() .send()
@ -24,14 +20,11 @@ async fn test_simple() {
.unwrap(); .unwrap();
assert_eq!(res.status(), 200); assert_eq!(res.status(), 200);
let mut h = HashMap::new();
h.insert("accept".to_string(), "application/octet-stream".to_string());
let res2 = ctx.k2v.request let res2 = ctx.k2v.request
.builder(bucket.clone()) .builder(bucket.clone())
.path("root".into()) .path("root".into())
.query_params(query_params.clone()) .query_param("sort_key", Some("test1"))
.signed_headers(h) .signed_header("accept", "application/octet-stream")
.body_signature(BodySignature::Classic) .body_signature(BodySignature::Classic)
.send() .send()
.await .await