1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-24 22:37:35 +02:00

hide httpmessage mod

This commit is contained in:
Rob Ede
2021-02-11 22:39:54 +00:00
parent 871ca5e4ae
commit 77efc09362
35 changed files with 125 additions and 98 deletions

View File

@ -1,6 +1,10 @@
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{fmt, mem};
//! Traits and structures to aid consuming and writing HTTP payloads.
use std::{
fmt, mem,
pin::Pin,
task::{Context, Poll},
};
use bytes::{Bytes, BytesMut};
use futures_core::{ready, Stream};
@ -8,8 +12,8 @@ use pin_project::pin_project;
use crate::error::Error;
/// Body size hint.
#[derive(Debug, PartialEq, Copy, Clone)]
/// Body size hint
pub enum BodySize {
None,
Empty,
@ -23,7 +27,7 @@ impl BodySize {
}
}
/// Type that provides this trait can be streamed to a peer.
/// Type that implement this trait can be streamed to a peer.
pub trait MessageBody {
fn size(&self) -> BodySize;
@ -80,7 +84,7 @@ impl ResponseBody<Body> {
impl<B> ResponseBody<B> {
pub fn take_body(&mut self) -> ResponseBody<B> {
std::mem::replace(self, ResponseBody::Other(Body::None))
mem::replace(self, ResponseBody::Other(Body::None))
}
}
@ -127,7 +131,7 @@ impl<B: MessageBody> Stream for ResponseBody<B> {
}
}
/// Represents various types of http message body.
/// Represents various types of HTTP message body.
pub enum Body {
/// Empty response. `Content-Length` header is not set.
None,

View File

@ -34,7 +34,8 @@ enum SslConnector {
#[cfg(not(any(feature = "openssl", feature = "rustls")))]
type SslConnector = ();
/// Manages http client network connectivity
/// Manages HTTP client network connectivity.
///
/// The `Connector` type uses a builder-like combinator pattern for service
/// construction that finishes by calling the `.finish()` method.
///
@ -160,8 +161,9 @@ where
self
}
/// Maximum supported http major version
/// Supported versions http/1.1, http/2
/// Maximum supported HTTP major version.
///
/// Supported versions are HTTP/1.1 and HTTP/2.
pub fn max_http_version(mut self, val: http::Version) -> Self {
let versions = match val {
http::Version::HTTP_11 => vec![b"http/1.1".to_vec()],

View File

@ -65,13 +65,16 @@ impl From<actix_tls::connect::ConnectError> for ConnectError {
#[derive(Debug, Display, From)]
pub enum InvalidUrl {
#[display(fmt = "Missing url scheme")]
#[display(fmt = "Missing URL scheme")]
MissingScheme,
#[display(fmt = "Unknown url scheme")]
#[display(fmt = "Unknown URL scheme")]
UnknownScheme,
#[display(fmt = "Missing host name")]
MissingHost,
#[display(fmt = "Url parse error: {}", _0)]
#[display(fmt = "URL parse error: {}", _0)]
HttpError(http::Error),
}
@ -83,25 +86,33 @@ pub enum SendRequestError {
/// Invalid URL
#[display(fmt = "Invalid URL: {}", _0)]
Url(InvalidUrl),
/// Failed to connect to host
#[display(fmt = "Failed to connect to host: {}", _0)]
Connect(ConnectError),
/// Error sending request
Send(io::Error),
/// Error parsing response
Response(ParseError),
/// Http error
#[display(fmt = "{}", _0)]
Http(HttpError),
/// Http2 error
#[display(fmt = "{}", _0)]
H2(h2::Error),
/// Response took too long
#[display(fmt = "Timeout while waiting for response")]
Timeout,
/// Tunnels are not supported for http2 connection
/// Tunnels are not supported for HTTP/2 connection
#[display(fmt = "Tunnels are not supported for http2 connection")]
TunnelNotSupported,
/// Error sending request body
Body(Error),
}
@ -127,7 +138,8 @@ pub enum FreezeRequestError {
/// Invalid URL
#[display(fmt = "Invalid URL: {}", _0)]
Url(InvalidUrl),
/// Http error
/// HTTP error
#[display(fmt = "{}", _0)]
Http(HttpError),
}

View File

@ -1,4 +1,5 @@
//! Http client api
//! HTTP client.
use http::Uri;
mod config;

View File

@ -95,32 +95,32 @@ impl ServiceConfig {
}))
}
/// Returns true if connection is secure (HTTPS)
#[inline]
/// Returns true if connection is secure(https)
pub fn secure(&self) -> bool {
self.0.secure
}
#[inline]
/// Returns the local address that this server is bound to.
#[inline]
pub fn local_addr(&self) -> Option<net::SocketAddr> {
self.0.local_addr
}
#[inline]
/// Keep alive duration if configured.
#[inline]
pub fn keep_alive(&self) -> Option<Duration> {
self.0.keep_alive
}
#[inline]
/// Return state of connection keep-alive functionality
#[inline]
pub fn keep_alive_enabled(&self) -> bool {
self.0.ka_enabled
}
#[inline]
/// Client timeout for first request.
#[inline]
pub fn client_timer(&self) -> Option<Sleep> {
let delay_time = self.0.client_timeout;
if delay_time != 0 {

View File

@ -1,7 +1,7 @@
use std::future::Future;
use std::io::{self, Write};
use std::pin::Pin;
//! Stream decoders.
use std::task::{Context, Poll};
use std::{future::Future, io, io::Write as _, pin::Pin};
use actix_rt::task::{spawn_blocking, JoinHandle};
use brotli2::write::BrotliDecoder;

View File

@ -1,8 +1,7 @@
//! Stream encoder
use std::future::Future;
use std::io::{self, Write};
use std::pin::Pin;
//! Stream encoders.
use std::task::{Context, Poll};
use std::{future::Future, io, io::Write as _, pin::Pin};
use actix_rt::task::{spawn_blocking, JoinHandle};
use brotli2::write::BrotliEncoder;

View File

@ -1,4 +1,5 @@
//! Content-Encoding support
//! Content-Encoding support.
use std::io;
use bytes::{Bytes, BytesMut};

View File

@ -38,7 +38,7 @@ pub type Result<T, E = Error> = result::Result<T, E>;
/// converting errors with `into()`.
///
/// Whenever it is created from an external object a response error is created
/// for it that can be used to create an http response from it this means that
/// for it that can be used to create an HTTP response from it this means that
/// if you have access to an actix `Error` you can always get a
/// `ResponseError` reference from it.
pub struct Error {
@ -404,7 +404,7 @@ impl ResponseError for crate::cookie::ParseError {
}
#[derive(Debug, Display, From)]
/// A set of errors that can occur during dispatching http requests
/// A set of errors that can occur during dispatching HTTP requests
pub enum DispatchError {
/// Service error
Service(Error),

View File

@ -178,7 +178,7 @@ where
)
}
/// Create http/1 dispatcher with slow request timeout.
/// Create HTTP/1 dispatcher with slow request timeout.
pub(crate) fn with_timeout(
io: T,
codec: Codec,

View File

@ -1,4 +1,4 @@
//! HTTP/1 implementation
//! HTTP/1 protocol implementation.
use bytes::{Bytes, BytesMut};
mod client;

View File

@ -1,4 +1,4 @@
//! HTTP/2 implementation.
//! HTTP/2 protocol.
use std::{
pin::Pin,

View File

@ -243,7 +243,7 @@ where
}
}
/// `Service` implementation for http/2 transport
/// `Service` implementation for HTTP/2 transport
pub struct H2ServiceHandler<T, S, B>
where
S: Service<Request>,

View File

@ -1,4 +1,6 @@
//! Helper trait for types that can be effectively borrowed as a [HeaderValue].
//!
//! [HeaderValue]: crate::http::HeaderValue
use std::{borrow::Cow, str::FromStr};

View File

@ -25,8 +25,8 @@ pub mod encoding;
mod extensions;
mod header;
mod helpers;
mod httpcodes;
pub mod httpmessage;
mod http_codes;
mod httpmessage;
mod message;
mod payload;
mod request;

View File

@ -107,7 +107,7 @@ impl<P> Request<P> {
#[inline]
#[doc(hidden)]
/// Mutable reference to a http message part of the request
/// Mutable reference to a HTTP message part of the request
pub fn head_mut(&mut self) -> &mut RequestHead {
&mut *self.head
}
@ -158,10 +158,12 @@ impl<P> Request<P> {
self.head().method == Method::CONNECT
}
/// Peer socket address
/// Peer socket address.
///
/// Peer address is actual socket address, if proxy is used in front of
/// actix http server, then peer address would be address of this proxy.
/// Peer address is the directly connected peer's socket address. If a proxy is used in front of
/// the Actix Web server, then it would be address of this proxy.
///
/// Will only return None when called in unit tests.
#[inline]
pub fn peer_addr(&self) -> Option<net::SocketAddr> {
self.head().peer_addr

View File

@ -32,13 +32,13 @@ pub struct Response<B = Body> {
}
impl Response<Body> {
/// Create http response builder with specific status.
/// Create HTTP response builder with specific status.
#[inline]
pub fn build(status: StatusCode) -> ResponseBuilder {
ResponseBuilder::new(status)
}
/// Create http response builder
/// Create HTTP response builder
#[inline]
pub fn build_from<T: Into<ResponseBuilder>>(source: T) -> ResponseBuilder {
source.into()
@ -97,7 +97,7 @@ impl<B> Response<B> {
}
#[inline]
/// Mutable reference to a http message part of the response
/// Mutable reference to a HTTP message part of the response
pub fn head_mut(&mut self) -> &mut ResponseHead {
&mut *self.head
}

View File

@ -432,7 +432,7 @@ where
}
}
/// `Service` implementation for http transport
/// `Service` implementation for HTTP transport
pub struct HttpServiceHandler<T, S, B, X, U>
where
S: Service<Request>,

View File

@ -7,7 +7,7 @@ use std::io;
use actix_http::error::{ErrorBadRequest, PayloadError};
use actix_http::http::header::{self, HeaderName, HeaderValue};
use actix_http::http::{Method, StatusCode, Version};
use actix_http::httpmessage::HttpMessage;
use actix_http::HttpMessage;
use actix_http::{body, Error, HttpService, Request, Response};
use actix_http_test::test_server;
use actix_service::{fn_service, ServiceFactoryExt};

View File

@ -10,7 +10,7 @@ use futures_util::future::{self, err, ok, ready, FutureExt};
use futures_util::stream::{once, StreamExt};
use regex::Regex;
use actix_http::httpmessage::HttpMessage;
use actix_http::HttpMessage;
use actix_http::{
body, error, http, http::header, Error, HttpService, KeepAlive, Request, Response,
};