Type Definition qiniu_http_client::SyncRequestBuilder
source · pub type SyncRequestBuilder<'r, E> = RequestBuilder<'r, SyncRequestBody<'r>, E>;
Expand description
阻塞请求构建器
Implementations§
source§impl<'r, E: 'r> SyncRequestBuilder<'r, E>
impl<'r, E: 'r> SyncRequestBuilder<'r, E>
sourcepub fn stream_as_body(
&mut self,
body: impl Read + Reset + Debug + Send + Sync + 'static,
content_length: u64,
content_type: Option<Mime>
) -> &mut Self
pub fn stream_as_body(
&mut self,
body: impl Read + Reset + Debug + Send + Sync + 'static,
content_length: u64,
content_type: Option<Mime>
) -> &mut Self
设置 HTTP 请求体为输入流
sourcepub fn referenced_stream_as_body<T: Read + Reset + 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: Read + Reset + 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 684)
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
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 fn multipart<'a>(&mut self, multipart: impl Into<SyncMultipart<'a>>) -> IoResult<&mut Self> {
let mut buf = Vec::new();
let multipart = multipart.into();
let mime = ("multipart/form-data; boundary=".to_owned() + multipart.boundary())
.parse()
.unwrap();
multipart.into_read().read_to_end(&mut buf)?;
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 对象
source§impl<'r, E: EndpointsProvider + Clone + 'r> SyncRequestBuilder<'r, E>
impl<'r, E: EndpointsProvider + Clone + 'r> SyncRequestBuilder<'r, E>
sourcepub fn call(&mut self) -> ApiResult<SyncResponse>
pub fn call(&mut self) -> ApiResult<SyncResponse>
阻塞发起 HTTP 请求
Examples found in repository?
More examples
src/regions/regions_provider/bucket_regions_queryer.rs (line 295)
286 287 288 289 290 291 292 293 294 295 296 297 298
fn do_sync_query(&self) -> ApiResult<GotRegions> {
handle_response_body(
self.queryer
.http_client
.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()?
.parse_json::<ResponseBody>()?,
)
}
src/regions/endpoints_provider/bucket_domains_provider.rs (line 281)
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
fn do_sync_query(&self) -> ApiResult<Endpoints> {
let endpoints: Endpoints = self
.queryer
.http_client
.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()?
.parse_json::<Vec<String>>()?
.into_body()
.into_iter()
.map(Endpoint::from)
.collect();
Ok(endpoints)
}