pub struct RequestBuilder<'r, B: 'r, E: 'r> { /* private fields */ }
Expand description

请求构建器

通过 HttpClient::getHttpClient::post 等方法创建请求构建器

Implementations§

设置是否使用 HTTPS

设置 HTTP 协议版本

设置 HTTP 请求路径

Examples found in repository?
src/regions/regions_provider/all_regions_provider.rs (line 261)
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
        fn do_sync_query(&self) -> ApiResult<GotRegions> {
            handle_response_body(
                self.http_client
                    .get(&[ServiceName::Uc], &self.uc_endpoints)
                    .path("/regions")
                    .authorization(Authorization::v2(&self.credential_provider))
                    .accept_json()
                    .call()?
                    .parse_json::<ResponseBody>()?,
            )
        }

        #[cfg(feature = "async")]
        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
Hide additional examples
src/regions/regions_provider/bucket_regions_queryer.rs (line 291)
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
    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>()?,
        )
    }

    #[cfg(feature = "async")]
    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 277)
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    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)
    }

    #[cfg(feature = "async")]
    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)
    }

设置 HTTP 请求头

添加 HTTP 请求头

设置 HTTP 响应预期为 JSON 类型

Examples found in repository?
src/regions/regions_provider/all_regions_provider.rs (line 263)
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
        fn do_sync_query(&self) -> ApiResult<GotRegions> {
            handle_response_body(
                self.http_client
                    .get(&[ServiceName::Uc], &self.uc_endpoints)
                    .path("/regions")
                    .authorization(Authorization::v2(&self.credential_provider))
                    .accept_json()
                    .call()?
                    .parse_json::<ResponseBody>()?,
            )
        }

        #[cfg(feature = "async")]
        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
Hide additional examples
src/regions/regions_provider/bucket_regions_queryer.rs (line 294)
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
    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>()?,
        )
    }

    #[cfg(feature = "async")]
    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 280)
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    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)
    }

    #[cfg(feature = "async")]
    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)
    }

设置 HTTP 响应预期为二进制流类型

设置查询参数

设置查询参数

追加查询参数

Examples found in repository?
src/regions/regions_provider/bucket_regions_queryer.rs (line 292)
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
    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>()?,
        )
    }

    #[cfg(feature = "async")]
    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?,
        )
    }
More examples
Hide additional examples
src/regions/endpoints_provider/bucket_domains_provider.rs (line 279)
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    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)
    }

    #[cfg(feature = "async")]
    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)
    }

追加 UserAgent

设置鉴权签名

Examples found in repository?
src/regions/regions_provider/all_regions_provider.rs (line 262)
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
        fn do_sync_query(&self) -> ApiResult<GotRegions> {
            handle_response_body(
                self.http_client
                    .get(&[ServiceName::Uc], &self.uc_endpoints)
                    .path("/regions")
                    .authorization(Authorization::v2(&self.credential_provider))
                    .accept_json()
                    .call()?
                    .parse_json::<ResponseBody>()?,
            )
        }

        #[cfg(feature = "async")]
        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
Hide additional examples
src/regions/endpoints_provider/bucket_domains_provider.rs (line 278)
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    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)
    }

    #[cfg(feature = "async")]
    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)
    }

设置为幂等请求

设置扩展信息

添加扩展信息

设置上传进度回调函数

设置响应状态码回调函数

设置响应 HTTP 头回调函数

设置域名解析前回调函数

设置域名解析成功回调函数

设置 IP 地址选择前回调函数

设置 IP 地址选择成功回调函数

设置 HTTP 请求签名前回调函数

设置 HTTP 请求前回调函数

设置响应成功回调函数

设置响应错误回调函数

设置退避前回调函数

设置退避后回调函数

获取 HTTP 请求构建器部分参数

获取 HTTP 请求构建器部分参数的可变引用

转换为 HTTP 请求构建器部分参数

设置 HTTP 请求体为输入流

设置 HTTP 请求体为输入流的可变引用

设置 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)))
    }

设置 HTTP 请求体为内存数据的引用

设置 HTTP 请求体为 JSON 对象

设置 HTTP 请求体为表单对象

设置 HTTP 请求体为 Multipart 表单对象

阻塞发起 HTTP 请求

Examples found in repository?
src/regions/regions_provider/all_regions_provider.rs (line 264)
257
258
259
260
261
262
263
264
265
266
267
        fn do_sync_query(&self) -> ApiResult<GotRegions> {
            handle_response_body(
                self.http_client
                    .get(&[ServiceName::Uc], &self.uc_endpoints)
                    .path("/regions")
                    .authorization(Authorization::v2(&self.credential_provider))
                    .accept_json()
                    .call()?
                    .parse_json::<ResponseBody>()?,
            )
        }
More examples
Hide additional 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)
    }

设置 HTTP 请求体为异步输入流

设置 HTTP 请求体为异步输入流的可变引用

设置 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)))
    }

设置 HTTP 请求体为内存数据的引用

设置 HTTP 请求体为 JSON 对象

设置 HTTP 请求体为表单对象

设置 HTTP 请求体为 Multipart 表单对象

异步发起 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
Hide additional 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)
    }

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts self into T using Into<T>. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function.
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function.
Should always be Self
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds.
Calls .tap_borrow() only in debug builds, and is erased in release builds.
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Calls .tap_ref() only in debug builds, and is erased in release builds.
Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Calls .tap_deref() only in debug builds, and is erased in release builds.
Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Attempts to convert self into T using TryInto<T>. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more