3个版本 (1个稳定版)
1.0.0 | 2024年1月11日 |
---|---|
0.1.0 | 2024年1月10日 |
0.0.1 | 2024年1月10日 |
#174 in HTTP客户端
46KB
844 行
通用S3头部
仅包含与S3-like服务通信所必需的头部信息。这正是你所需要的。
获取
// Get from S3 from some location.
let url = Url::from_str("https://example.s3.amazonaws.com/test/test.json").unwrap();
let headers = S3HeadersBuilder::new(&url)
.set_access_key(&access_key)
.set_secret_key(&secret_key)
.set_region(®ion)
.set_method("GET")
.set_service("s3")
.build();
// Use Reqwest or any other library!
let response = reqwest::blocking::Client::new()
.get(url)
.headers(reqwest::header::HeaderMap::from_iter(headers.into_iter().map(
|(k, v)| {
(
reqwest::header::HeaderName::from_str(k).unwrap(),
reqwest::header::HeaderValue::from_str(&v).unwrap(),
)
},
)))
.send()
.unwrap();
放置
// We want to put content into S3.
let url = Url::from_str("https://example.s3.amazonaws.com/test/test.json").unwrap();
let content = "{\"c\":\"d\"}\n".as_bytes().to_vec();
// Build the S3 headers.
let (access_key, secret_key, region) = setup::get_config_from_env("TEST_S3");
let headers = S3HeadersBuilder::new(&url)
.set_access_key(&access_key)
.set_secret_key(&secret_key)
.set_region(®ion)
.set_method(PUT_METHOD)
.set_service("s3")
.set_payload_hash_with_content(&content)
.build();
// Use Reqwest or any other library!
let response = reqwest::blocking::Client::new()
.put(url)
.headers(reqwest::header::HeaderMap::from_iter(headers.into_iter().map(
|(k, v)| {
(
reqwest::header::HeaderName::from_str(k).unwrap(),
reqwest::header::HeaderValue::from_str(&v).unwrap(),
)
},
)))
.send()
.unwrap();
列出
let url = Url::from_str("https://example.s3.amazonaws.com/").unwrap();
let headers = S3HeadersBuilder::new(&url)
.set_access_key(&access_key)
.set_secret_key(&secret_key)
.set_region(®ion)
.set_method("GET")
.set_service("s3")
.build();
// Use Reqwest or any other library!
let response = reqwest::blocking::Client::new()
.get(url)
.headers(reqwest::header::HeaderMap::from_iter(headers.into_iter().map(
|(k, v)| {
(
reqwest::header::HeaderName::from_str(k).unwrap(),
reqwest::header::HeaderValue::from_str(&v).unwrap(),
)
},
)))
.send()
.unwrap();
依赖项
~2.5MB
~72K SLoC