Struct qiniu_http::Response
source · pub struct Response<B> { /* private fields */ }
Expand description
HTTP 响应
封装 HTTP 响应相关字段
Implementations§
source§impl<B> Response<B>
impl<B> Response<B>
sourcepub fn parts(&self) -> &ResponseParts
pub fn parts(&self) -> &ResponseParts
HTTP 响应信息
sourcepub fn parts_mut(&mut self) -> &mut ResponseParts
pub fn parts_mut(&mut self) -> &mut ResponseParts
获取 HTTP 响应信息的可变引用
sourcepub fn into_parts_and_body(self) -> (ResponseParts, B)
pub fn into_parts_and_body(self) -> (ResponseParts, B)
转换为响应信息和响应体
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)),
}
}
sourcepub fn from_parts_and_body(parts: ResponseParts, body: B) -> Self
pub fn from_parts_and_body(parts: ResponseParts, body: B) -> Self
通过响应信息和响应体创建 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)),
}
}
Methods from Deref<Target = ResponseParts>§
sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
获取 HTTP 状态码
sourcepub fn status_code_mut(&mut self) -> &mut StatusCode
pub fn status_code_mut(&mut self) -> &mut StatusCode
获取 HTTP 状态码 的可变引用
sourcepub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
获取 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
}
sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
获取 扩展信息
sourcepub fn header(&self, header_name: impl AsHeaderName) -> Option<&HeaderValue>
pub fn header(&self, header_name: impl AsHeaderName) -> Option<&HeaderValue>
获取 HTTP 响应 Header
sourcepub fn server_ip_mut(&mut self) -> &mut Option<IpAddr>
pub fn server_ip_mut(&mut self) -> &mut Option<IpAddr>
获取 HTTP 服务器 IP 地址的可变引用
sourcepub fn server_port(&self) -> Option<NonZeroU16>
pub fn server_port(&self) -> Option<NonZeroU16>
获取 HTTP 服务器端口号
sourcepub fn server_port_mut(&mut self) -> &mut Option<NonZeroU16>
pub fn server_port_mut(&mut self) -> &mut Option<NonZeroU16>
获取 HTTP 服务器端口号的可变引用
sourcepub fn metrics_mut(&mut self) -> &mut Option<Metrics>
pub fn metrics_mut(&mut self) -> &mut Option<Metrics>
获取 HTTP 响应的指标信息的可变引用