1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-10 17:29:36 +00:00

hide httpmessage mod

This commit is contained in:
Rob Ede 2021-02-11 22:39:54 +00:00
parent 871ca5e4ae
commit 77efc09362
No known key found for this signature in database
GPG key ID: C2A3B36E841A91E6
35 changed files with 125 additions and 98 deletions

View file

@ -150,7 +150,7 @@ impl TestServer {
}
}
/// Construct test https server url
/// Construct test HTTPS server URL.
pub fn surl(&self, uri: &str) -> String {
if uri.starts_with('/') {
format!("https://localhost:{}{}", self.addr.port(), uri)
@ -164,7 +164,7 @@ impl TestServer {
self.client.get(self.url(path.as_ref()).as_str())
}
/// Create https `GET` request
/// Create HTTPS `GET` request
pub fn sget<S: AsRef<str>>(&self, path: S) -> ClientRequest {
self.client.get(self.surl(path.as_ref()).as_str())
}
@ -174,7 +174,7 @@ impl TestServer {
self.client.post(self.url(path.as_ref()).as_str())
}
/// Create https `POST` request
/// Create HTTPS `POST` request
pub fn spost<S: AsRef<str>>(&self, path: S) -> ClientRequest {
self.client.post(self.surl(path.as_ref()).as_str())
}
@ -184,7 +184,7 @@ impl TestServer {
self.client.head(self.url(path.as_ref()).as_str())
}
/// Create https `HEAD` request
/// Create HTTPS `HEAD` request
pub fn shead<S: AsRef<str>>(&self, path: S) -> ClientRequest {
self.client.head(self.surl(path.as_ref()).as_str())
}
@ -194,7 +194,7 @@ impl TestServer {
self.client.put(self.url(path.as_ref()).as_str())
}
/// Create https `PUT` request
/// Create HTTPS `PUT` request
pub fn sput<S: AsRef<str>>(&self, path: S) -> ClientRequest {
self.client.put(self.surl(path.as_ref()).as_str())
}
@ -204,7 +204,7 @@ impl TestServer {
self.client.patch(self.url(path.as_ref()).as_str())
}
/// Create https `PATCH` request
/// Create HTTPS `PATCH` request
pub fn spatch<S: AsRef<str>>(&self, path: S) -> ClientRequest {
self.client.patch(self.surl(path.as_ref()).as_str())
}
@ -214,7 +214,7 @@ impl TestServer {
self.client.delete(self.url(path.as_ref()).as_str())
}
/// Create https `DELETE` request
/// Create HTTPS `DELETE` request
pub fn sdelete<S: AsRef<str>>(&self, path: S) -> ClientRequest {
self.client.delete(self.surl(path.as_ref()).as_str())
}
@ -224,12 +224,12 @@ impl TestServer {
self.client.options(self.url(path.as_ref()).as_str())
}
/// Create https `OPTIONS` request
/// Create HTTPS `OPTIONS` request
pub fn soptions<S: AsRef<str>>(&self, path: S) -> ClientRequest {
self.client.options(self.surl(path.as_ref()).as_str())
}
/// Connect to test http server
/// Connect to test HTTP server
pub fn request<S: AsRef<str>>(&self, method: Method, path: S) -> ClientRequest {
self.client.request(method, path.as_ref())
}
@ -263,7 +263,7 @@ impl TestServer {
self.ws_at("/").await
}
/// Stop http server
/// Stop HTTP server
fn stop(&mut self) {
self.system.stop();
}

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,
};

View file

@ -15,7 +15,7 @@ use bytes::Bytes;
use futures_core::Stream;
use tokio::sync::oneshot::Sender;
/// Execution context for http actors
/// Execution context for HTTP actors
pub struct HttpContext<A>
where
A: Actor<Context = HttpContext<A>>,

View file

@ -82,8 +82,9 @@ impl ClientBuilder {
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 {
self.max_http_version = Some(val);
self

View file

@ -134,7 +134,7 @@ use self::connect::{Connect, ConnectorWrapper};
///
/// let res = client.get("http://www.rust-lang.org") // <- Create request builder
/// .insert_header(("User-Agent", "Actix-web"))
/// .send() // <- Send http request
/// .send() // <- Send HTTP request
/// .await; // <- send request and wait for response
///
/// println!("Response: {:?}", res);

View file

@ -42,10 +42,10 @@ cfg_if::cfg_if! {
/// let response = awc::Client::new()
/// .get("http://www.rust-lang.org") // <- Create request builder
/// .insert_header(("User-Agent", "Actix-web"))
/// .send() // <- Send http request
/// .send() // <- Send HTTP request
/// .await;
///
/// response.and_then(|response| { // <- server http response
/// response.and_then(|response| { // <- server HTTP response
/// println!("Response: {:?}", response);
/// Ok(())
/// });
@ -219,7 +219,7 @@ impl ClientRequest {
}
/// Force close connection instead of returning it back to connections pool.
/// This setting affect only http/1 connections.
/// This setting affect only HTTP/1 connections.
#[inline]
pub fn force_close(mut self) -> Self {
self.head.set_connection_type(ConnectionType::Close);

View file

@ -109,7 +109,7 @@ impl<S> ClientResponse<S>
where
S: Stream<Item = Result<Bytes, PayloadError>>,
{
/// Loads http response's body.
/// Loads HTTP response's body.
pub fn body(&mut self) -> MessageBody<S> {
MessageBody::new(self)
}
@ -151,7 +151,7 @@ impl<S> fmt::Debug for ClientResponse<S> {
}
}
/// Future that resolves to a complete http message body.
/// Future that resolves to a complete HTTP message body.
pub struct MessageBody<S> {
length: Option<usize>,
err: Option<PayloadError>,

View file

@ -72,7 +72,7 @@ where
/// Set application data. Application data could be accessed
/// by using `Data<T>` extractor where `T` is data type.
///
/// **Note**: http server accepts an application factory rather than
/// **Note**: HTTP server accepts an application factory rather than
/// an application instance. Http server constructs an application
/// instance for each thread, thus application data must be constructed
/// multiple times. If you want to share data between different
@ -207,7 +207,7 @@ where
)
}
/// Register http service.
/// Register HTTP service.
///
/// Http service is any type that implements `HttpServiceFactory` trait.
///

View file

@ -27,7 +27,7 @@ pub(crate) type FnDataFactory =
///
/// Application data can be accessed by using `Data<T>` extractor where `T` is data type.
///
/// **Note**: http server accepts an application factory rather than an application instance. HTTP
/// **Note**: HTTP server accepts an application factory rather than an application instance. HTTP
/// server constructs an application instance for each thread, thus application data must be
/// constructed multiple times. If you want to share data between different threads, a shareable
/// object should be used, e.g. `Send + Sync`. Application data does not need to be `Send`

View file

@ -176,7 +176,7 @@ impl Guard for NotGuard {
}
}
/// Http method guard
/// HTTP method guard.
#[doc(hidden)]
pub struct MethodGuard(http::Method);
@ -186,52 +186,52 @@ impl Guard for MethodGuard {
}
}
/// Guard to match *GET* http method
/// Guard to match *GET* HTTP method.
pub fn Get() -> MethodGuard {
MethodGuard(http::Method::GET)
}
/// Predicate to match *POST* http method
/// Predicate to match *POST* HTTP method.
pub fn Post() -> MethodGuard {
MethodGuard(http::Method::POST)
}
/// Predicate to match *PUT* http method
/// Predicate to match *PUT* HTTP method.
pub fn Put() -> MethodGuard {
MethodGuard(http::Method::PUT)
}
/// Predicate to match *DELETE* http method
/// Predicate to match *DELETE* HTTP method.
pub fn Delete() -> MethodGuard {
MethodGuard(http::Method::DELETE)
}
/// Predicate to match *HEAD* http method
/// Predicate to match *HEAD* HTTP method.
pub fn Head() -> MethodGuard {
MethodGuard(http::Method::HEAD)
}
/// Predicate to match *OPTIONS* http method
/// Predicate to match *OPTIONS* HTTP method.
pub fn Options() -> MethodGuard {
MethodGuard(http::Method::OPTIONS)
}
/// Predicate to match *CONNECT* http method
/// Predicate to match *CONNECT* HTTP method.
pub fn Connect() -> MethodGuard {
MethodGuard(http::Method::CONNECT)
}
/// Predicate to match *PATCH* http method
/// Predicate to match *PATCH* HTTP method.
pub fn Patch() -> MethodGuard {
MethodGuard(http::Method::PATCH)
}
/// Predicate to match *TRACE* http method
/// Predicate to match *TRACE* HTTP method.
pub fn Trace() -> MethodGuard {
MethodGuard(http::Method::TRACE)
}
/// Predicate to match specified http method
/// Predicate to match specified HTTP method.
pub fn Method(method: http::Method) -> MethodGuard {
MethodGuard(method)
}

View file

@ -62,7 +62,7 @@ impl HttpRequest {
}
/// This method returns mutable reference to the request head.
/// panics if multiple references of http request exists.
/// panics if multiple references of HTTP request exists.
#[inline]
pub(crate) fn head_mut(&mut self) -> &mut RequestHead {
&mut Rc::get_mut(&mut self.inner).unwrap().head
@ -202,12 +202,14 @@ impl HttpRequest {
&self.app_state().rmap()
}
/// 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.
///
/// To get client connection information `.connection_info()` should be used.
///
/// Will only return None when called in unit tests.
#[inline]
pub fn peer_addr(&self) -> Option<net::SocketAddr> {
self.head().peer_addr

View file

@ -40,7 +40,7 @@ struct Config {
/// An HTTP Server.
///
/// Create new http server with application factory.
/// Create new HTTP server with application factory.
///
/// ```rust,no_run
/// use actix_web::{web, App, HttpResponse, HttpServer};
@ -86,7 +86,7 @@ where
S::Service: 'static,
B: MessageBody + 'static,
{
/// Create new http server with application factory
/// Create new HTTP server with application factory
pub fn new(factory: F) -> Self {
HttpServer {
factory,
@ -131,8 +131,7 @@ where
/// Set number of workers to start.
///
/// By default http server uses number of available logical cpu as threads
/// count.
/// By default, server uses number of available logical CPU as thread count.
pub fn workers(mut self, num: usize) -> Self {
self.builder = self.builder.workers(num);
self
@ -257,7 +256,7 @@ where
/// Get addresses of bound sockets and the scheme for it.
///
/// This is useful when the server is bound from different sources
/// with some sockets listening on http and some listening on https
/// with some sockets listening on HTTP and some listening on HTTPS
/// and the user should be presented with an enumeration of which
/// socket requires which protocol.
pub fn addrs_with_scheme(&self) -> Vec<(net::SocketAddr, &str)> {
@ -610,7 +609,7 @@ where
{
/// Start listening for incoming connections.
///
/// This method starts number of http workers in separate threads.
/// This method starts number of HTTP workers in separate threads.
/// For each address this method starts separate thread which does
/// `accept()` in a loop.
///

View file

@ -164,12 +164,14 @@ impl ServiceRequest {
}
}
/// 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.
///
/// To get client connection information `ConnectionInfo` should be used.
///
/// Will only return None when called in unit tests.
#[inline]
pub fn peer_addr(&self) -> Option<net::SocketAddr> {
self.head().peer_addr

View file

@ -851,13 +851,13 @@ impl TestServerConfig {
}
}
/// Start http/1.1 server only
/// Start HTTP/1.1 server only
pub fn h1(mut self) -> Self {
self.tp = HttpVer::Http1;
self
}
/// Start http/2 server only
/// Start HTTP/2 server only
pub fn h2(mut self) -> Self {
self.tp = HttpVer::Http2;
self
@ -956,7 +956,7 @@ impl TestServer {
self.client.options(self.url(path.as_ref()).as_str())
}
/// Connect to test http server
/// Connect to test HTTP server
pub fn request<S: AsRef<str>>(&self, method: Method, path: S) -> ClientRequest {
self.client.request(method, path.as_ref())
}
@ -990,7 +990,7 @@ impl TestServer {
self.ws_at("/").await
}
/// Gracefully stop http server
/// Gracefully stop HTTP server
pub async fn stop(self) {
self.server.stop(true).await;
self.system.stop();
@ -1006,7 +1006,7 @@ impl Drop for TestServer {
#[cfg(test)]
mod tests {
use actix_http::httpmessage::HttpMessage;
use actix_http::HttpMessage;
use serde::{Deserialize, Serialize};
use std::time::SystemTime;