Type Definition qiniu_http_client::AsyncRequestBuilder
source · pub type AsyncRequestBuilder<'r, E> = RequestBuilder<'r, AsyncRequestBody<'r>, E>;
Expand description
异步请求构建器
Implementations§
source§impl<'r, E: 'r> AsyncRequestBuilder<'r, E>
impl<'r, E: 'r> AsyncRequestBuilder<'r, E>
sourcepub fn stream_as_body(
&mut self,
body: impl AsyncRead + AsyncReset + Unpin + Debug + Send + Sync + 'static,
content_length: u64,
content_type: Option<Mime>
) -> &mut Self
pub fn stream_as_body(
&mut self,
body: impl AsyncRead + AsyncReset + Unpin + Debug + Send + Sync + 'static,
content_length: u64,
content_type: Option<Mime>
) -> &mut Self
设置 HTTP 请求体为异步输入流
sourcepub fn referenced_stream_as_body<T: AsyncRead + AsyncReset + Unpin + Debug + Send + Sync>(
&mut self,
body: &'r mut T,
content_length: u64,
content_type: Option<Mime>
) -> &mut Self
pub fn referenced_stream_as_body<T: AsyncRead + AsyncReset + Unpin + Debug + Send + Sync>(
&mut self,
body: &'r mut T,
content_length: u64,
content_type: Option<Mime>
) -> &mut Self
设置 HTTP 请求体为异步输入流的可变引用
sourcepub fn bytes_as_body(
&mut self,
body: impl Into<Vec<u8>>,
content_type: Option<Mime>
) -> &mut Self
pub fn bytes_as_body(
&mut self,
body: impl Into<Vec<u8>>,
content_type: Option<Mime>
) -> &mut Self
设置 HTTP 请求体为内存数据
Examples found in repository?
src/client/request/builder.rs (line 793)
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
pub fn json(&mut self, body: impl Serialize) -> JsonResult<&mut Self> {
Ok(self.bytes_as_body(serde_json::to_vec(&body)?, Some(APPLICATION_JSON)))
}
/// 设置 HTTP 请求体为表单对象
#[inline]
pub fn post_form<I, K, V>(&mut self, iter: I) -> &mut Self
where
I: IntoIterator,
I::Item: Borrow<(K, Option<V>)>,
K: AsRef<str>,
V: AsRef<str>,
{
let mut form = form_urlencoded::Serializer::new(String::new());
for pair in iter {
let (k, v) = pair.borrow();
if let Some(v) = v {
form.append_pair(k.as_ref(), v.as_ref());
} else {
form.append_key_only(k.as_ref());
}
}
self.bytes_as_body(form.finish().into_bytes(), Some(APPLICATION_WWW_FORM_URLENCODED))
}
/// 设置 HTTP 请求体为 Multipart 表单对象
#[inline]
pub async fn multipart<'a>(
&mut self,
multipart: impl Into<AsyncMultipart<'a>>,
) -> IoResult<&mut RequestBuilder<'r, AsyncRequestBody<'r>, E>> {
use futures::AsyncReadExt;
let mut buf = Vec::new();
let multipart = multipart.into();
let mime = ("multipart/form-data; boundary=".to_owned() + multipart.boundary())
.parse()
.unwrap();
multipart.into_async_read().read_to_end(&mut buf).await?;
Ok(self.bytes_as_body(buf, Some(mime)))
}
sourcepub fn referenced_bytes_as_body(
&mut self,
body: &'r [u8],
content_type: Option<Mime>
) -> &mut Self
pub fn referenced_bytes_as_body(
&mut self,
body: &'r [u8],
content_type: Option<Mime>
) -> &mut Self
设置 HTTP 请求体为内存数据的引用
sourcepub fn json(&mut self, body: impl Serialize) -> JsonResult<&mut Self>
pub fn json(&mut self, body: impl Serialize) -> JsonResult<&mut Self>
设置 HTTP 请求体为 JSON 对象
sourcepub fn post_form<I, K, V>(&mut self, iter: I) -> &mut Selfwhere
I: IntoIterator,
I::Item: Borrow<(K, Option<V>)>,
K: AsRef<str>,
V: AsRef<str>,
pub fn post_form<I, K, V>(&mut self, iter: I) -> &mut Selfwhere
I: IntoIterator,
I::Item: Borrow<(K, Option<V>)>,
K: AsRef<str>,
V: AsRef<str>,
设置 HTTP 请求体为表单对象
sourcepub async fn multipart<'a>(
&mut self,
multipart: impl Into<AsyncMultipart<'a>>
) -> IoResult<&mut RequestBuilder<'r, AsyncRequestBody<'r>, E>>
pub async fn multipart<'a>(
&mut self,
multipart: impl Into<AsyncMultipart<'a>>
) -> IoResult<&mut RequestBuilder<'r, AsyncRequestBody<'r>, E>>
设置 HTTP 请求体为 Multipart 表单对象
source§impl<'r, E: EndpointsProvider + Clone + 'r> AsyncRequestBuilder<'r, E>
impl<'r, E: EndpointsProvider + Clone + 'r> AsyncRequestBuilder<'r, E>
sourcepub async fn call(&mut self) -> ApiResult<AsyncResponse>
pub async fn call(&mut self) -> ApiResult<AsyncResponse>
异步发起 HTTP 请求
Examples found in repository?
src/regions/regions_provider/all_regions_provider.rs (line 277)
270 271 272 273 274 275 276 277 278 279 280 281 282
async fn do_async_query(&self) -> ApiResult<GotRegions> {
handle_response_body(
self.http_client
.async_get(&[ServiceName::Uc], &self.uc_endpoints)
.path("/regions")
.authorization(Authorization::v2(&self.credential_provider))
.accept_json()
.call()
.await?
.parse_json::<ResponseBody>()
.await?,
)
}
More examples
src/regions/regions_provider/bucket_regions_queryer.rs (line 310)
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
async fn do_async_query(&self) -> ApiResult<GotRegions> {
handle_response_body(
self.queryer
.http_client
.async_get(&[ServiceName::Uc, ServiceName::Api], &self.queryer.uc_endpoints)
.path("/v4/query")
.append_query_pair("ak", self.access_key.as_str())
.append_query_pair("bucket", self.bucket_name.as_str())
.accept_json()
.call()
.await?
.parse_json::<ResponseBody>()
.await?,
)
}
src/regions/endpoints_provider/bucket_domains_provider.rs (line 300)
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
async fn do_async_query(&self) -> ApiResult<Endpoints> {
let endpoints: Endpoints = self
.queryer
.http_client
.async_get(&[ServiceName::Uc], &self.queryer.uc_endpoints)
.path("/v2/domains")
.authorization(Authorization::v2(&self.credential))
.append_query_pair("tbl", self.bucket_name.as_str())
.accept_json()
.call()
.await?
.parse_json::<Vec<String>>()
.await?
.into_body()
.into_iter()
.map(Endpoint::from)
.collect();
Ok(endpoints)
}