Struct qiniu_http::Response

source ·
pub struct Response<B> { /* private fields */ }
Expand description

HTTP 响应

封装 HTTP 响应相关字段

Implementations§

返回 HTTP 响应构建器

获取 HTTP 响应体

获取 HTTP 响应体的可变引用

Examples found in repository?
src/response.rs (line 501)
500
501
502
503
    pub fn body(&mut self, body: B) -> &mut Self {
        *self.inner.body_mut() = body;
        self
    }

HTTP 响应信息

获取 HTTP 响应信息的可变引用

转换为 HTTP 响应体

转换为响应信息和响应体

Examples found in repository?
src/response.rs (line 384)
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
    pub fn map_body<B2>(self, f: impl FnOnce(B) -> B2) -> Response<B2> {
        let (parts, body) = self.into_parts_and_body();
        let body = f(body);
        Response::from_parts_and_body(parts, body)
    }

    /// 尝试对 HTTP 响应体进行映射
    #[inline]
    pub fn try_map_body<B2, E>(
        self,
        f: impl FnOnce(B) -> result::Result<B2, E>,
    ) -> result::Result<Response<B2>, MapError<E>> {
        let (parts, body) = self.into_parts_and_body();
        match f(body) {
            Ok(body) => Ok(Response::from_parts_and_body(parts, body)),
            Err(err) => Err(MapError::new(err, parts)),
        }
    }

    /// 尝试对 HTTP 响应体进行异步映射
    #[inline]
    #[cfg(feature = "async")]
    pub async fn try_async_map_body<B2, E, F, Fut>(self, f: F) -> result::Result<Response<B2>, MapError<E>>
    where
        F: FnOnce(B) -> Fut,
        Fut: Future<Output = result::Result<B2, E>>,
    {
        let (parts, body) = self.into_parts_and_body();
        match f(body).await {
            Ok(body) => Ok(Response::from_parts_and_body(parts, body)),
            Err(err) => Err(MapError::new(err, parts)),
        }
    }

通过响应信息和响应体创建 HTTP 响应

Examples found in repository?
src/response.rs (line 386)
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
    pub fn map_body<B2>(self, f: impl FnOnce(B) -> B2) -> Response<B2> {
        let (parts, body) = self.into_parts_and_body();
        let body = f(body);
        Response::from_parts_and_body(parts, body)
    }

    /// 尝试对 HTTP 响应体进行映射
    #[inline]
    pub fn try_map_body<B2, E>(
        self,
        f: impl FnOnce(B) -> result::Result<B2, E>,
    ) -> result::Result<Response<B2>, MapError<E>> {
        let (parts, body) = self.into_parts_and_body();
        match f(body) {
            Ok(body) => Ok(Response::from_parts_and_body(parts, body)),
            Err(err) => Err(MapError::new(err, parts)),
        }
    }

    /// 尝试对 HTTP 响应体进行异步映射
    #[inline]
    #[cfg(feature = "async")]
    pub async fn try_async_map_body<B2, E, F, Fut>(self, f: F) -> result::Result<Response<B2>, MapError<E>>
    where
        F: FnOnce(B) -> Fut,
        Fut: Future<Output = result::Result<B2, E>>,
    {
        let (parts, body) = self.into_parts_and_body();
        match f(body).await {
            Ok(body) => Ok(Response::from_parts_and_body(parts, body)),
            Err(err) => Err(MapError::new(err, parts)),
        }
    }

对 HTTP 响应体进行映射

尝试对 HTTP 响应体进行映射

尝试对 HTTP 响应体进行异步映射

Methods from Deref<Target = ResponseParts>§

获取 HTTP 状态码

获取 HTTP 状态码 的可变引用

Examples found in repository?
src/response.rs (line 452)
451
452
453
454
    pub fn status_code(&mut self, status_code: StatusCode) -> &mut Self {
        *self.inner.status_code_mut() = status_code;
        self
    }

获取 HTTP Headers

Examples found in repository?
src/response.rs (line 265)
264
265
266
    pub fn header(&self, header_name: impl AsHeaderName) -> Option<&HeaderValue> {
        self.headers().get(header_name)
    }

获取 HTTP Headers 的可变引用

Examples found in repository?
src/response.rs (line 459)
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
    pub fn headers(&mut self, headers: HeaderMap) -> &mut Self {
        *self.inner.headers_mut() = headers;
        self
    }

    /// 设置 HTTP 版本
    #[inline]
    pub fn version(&mut self, version: Version) -> &mut Self {
        *self.inner.version_mut() = version;
        self
    }

    /// 设置 HTTP 服务器 IP 地址
    #[inline]
    pub fn server_ip(&mut self, server_ip: IpAddr) -> &mut Self {
        *self.inner.info.server_ip_mut() = Some(server_ip);
        self
    }

    /// 设置 HTTP 服务器端口号
    #[inline]
    pub fn server_port(&mut self, server_port: NonZeroU16) -> &mut Self {
        *self.inner.info.server_port_mut() = Some(server_port);
        self
    }

    /// 设置扩展信息
    #[inline]
    pub fn extensions(&mut self, extensions: Extensions) -> &mut Self {
        *self.inner.extensions_mut() = extensions;
        self
    }

    /// 添加 HTTP Header
    #[inline]
    pub fn header(&mut self, header_name: impl IntoHeaderName, header_value: impl Into<HeaderValue>) -> &mut Self {
        self.inner.headers_mut().insert(header_name, header_value.into());
        self
    }

获取 HTTP 版本

获取 HTTP 版本的可变引用

Examples found in repository?
src/response.rs (line 466)
465
466
467
468
    pub fn version(&mut self, version: Version) -> &mut Self {
        *self.inner.version_mut() = version;
        self
    }

获取 扩展信息

获取扩展信息的可变引用

Examples found in repository?
src/response.rs (line 487)
486
487
488
489
    pub fn extensions(&mut self, extensions: Extensions) -> &mut Self {
        *self.inner.extensions_mut() = extensions;
        self
    }

获取 HTTP 响应 Header

获取 HTTP 服务器 IP 地址

获取 HTTP 服务器 IP 地址的可变引用

获取 HTTP 服务器端口号

获取 HTTP 服务器端口号的可变引用

获取 HTTP 响应的指标信息

获取 HTTP 响应的指标信息的可变引用

Examples found in repository?
src/response.rs (line 508)
507
508
509
510
    pub fn metrics(&mut self, metrics: Metrics) -> &mut Self {
        *self.inner.metrics_mut() = Some(metrics);
        self
    }

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.

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

Returns the argument unchanged.

Calls U::from(self).

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

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.