2020-10-30 03:19:56 +01:00
|
|
|
//! HTTP primitives for the Actix ecosystem.
|
2021-02-13 16:08:43 +01:00
|
|
|
//!
|
|
|
|
//! ## Crate Features
|
2021-06-19 21:21:13 +02:00
|
|
|
//! | Feature | Functionality |
|
|
|
|
//! | ------------------- | ------------------------------------------- |
|
|
|
|
//! | `openssl` | TLS support via [OpenSSL]. |
|
|
|
|
//! | `rustls` | TLS support via [rustls]. |
|
|
|
|
//! | `compress-brotli` | Payload compression support: Brotli. |
|
|
|
|
//! | `compress-gzip` | Payload compression support: Deflate, Gzip. |
|
|
|
|
//! | `compress-zstd` | Payload compression support: Zstd. |
|
|
|
|
//! | `trust-dns` | Use [trust-dns] as the client DNS resolver. |
|
2021-02-13 16:08:43 +01:00
|
|
|
//!
|
|
|
|
//! [OpenSSL]: https://crates.io/crates/openssl
|
|
|
|
//! [rustls]: https://crates.io/crates/rustls
|
|
|
|
//! [trust-dns]: https://crates.io/crates/trust-dns
|
2020-09-10 15:46:35 +02:00
|
|
|
|
2021-12-08 07:09:56 +01:00
|
|
|
#![deny(rust_2018_idioms, nonstandard_style)]
|
|
|
|
#![warn(future_incompatible)]
|
2019-04-08 08:06:21 +02:00
|
|
|
#![allow(
|
|
|
|
clippy::type_complexity,
|
2019-07-17 09:55:44 +02:00
|
|
|
clippy::too_many_arguments,
|
2019-04-08 08:06:21 +02:00
|
|
|
clippy::new_without_default,
|
2019-12-13 05:59:02 +01:00
|
|
|
clippy::borrow_interior_mutable_const
|
2019-04-08 08:06:21 +02:00
|
|
|
)]
|
2020-10-30 03:19:56 +01:00
|
|
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
|
|
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
2019-03-26 19:54:35 +01:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
|
|
|
|
pub mod body;
|
|
|
|
mod builder;
|
|
|
|
mod config;
|
2021-06-19 21:21:13 +02:00
|
|
|
|
|
|
|
#[cfg(feature = "__compress")]
|
2019-03-26 23:14:32 +01:00
|
|
|
pub mod encoding;
|
2019-03-26 19:54:35 +01:00
|
|
|
mod extensions;
|
2021-04-19 04:29:38 +02:00
|
|
|
pub mod header;
|
2019-03-26 19:54:35 +01:00
|
|
|
mod helpers;
|
2021-02-11 23:58:35 +01:00
|
|
|
mod http_message;
|
2019-03-26 19:54:35 +01:00
|
|
|
mod message;
|
|
|
|
mod payload;
|
|
|
|
mod request;
|
|
|
|
mod response;
|
2021-04-14 03:12:47 +02:00
|
|
|
mod response_builder;
|
2019-03-26 19:54:35 +01:00
|
|
|
mod service;
|
|
|
|
|
|
|
|
pub mod error;
|
|
|
|
pub mod h1;
|
|
|
|
pub mod h2;
|
2019-11-18 13:42:27 +01:00
|
|
|
pub mod test;
|
|
|
|
pub mod ws;
|
2019-03-26 19:54:35 +01:00
|
|
|
|
|
|
|
pub use self::builder::HttpServiceBuilder;
|
|
|
|
pub use self::config::{KeepAlive, ServiceConfig};
|
2021-06-17 18:57:58 +02:00
|
|
|
pub use self::error::Error;
|
2019-03-26 19:54:35 +01:00
|
|
|
pub use self::extensions::Extensions;
|
2021-04-19 04:29:38 +02:00
|
|
|
pub use self::header::ContentEncoding;
|
2021-02-11 23:58:35 +01:00
|
|
|
pub use self::http_message::HttpMessage;
|
2021-04-19 04:29:38 +02:00
|
|
|
pub use self::message::ConnectionType;
|
2019-09-10 06:29:32 +02:00
|
|
|
pub use self::message::{Message, RequestHead, RequestHeadType, ResponseHead};
|
2019-03-26 19:54:35 +01:00
|
|
|
pub use self::payload::{Payload, PayloadStream};
|
|
|
|
pub use self::request::Request;
|
2021-04-14 06:20:45 +02:00
|
|
|
pub use self::response::Response;
|
|
|
|
pub use self::response_builder::ResponseBuilder;
|
2019-04-05 20:29:42 +02:00
|
|
|
pub use self::service::HttpService;
|
2019-03-26 19:54:35 +01:00
|
|
|
|
2021-04-19 04:29:38 +02:00
|
|
|
pub use ::http::{uri, uri::Uri};
|
|
|
|
pub use ::http::{Method, StatusCode, Version};
|
|
|
|
|
2021-01-06 19:58:24 +01:00
|
|
|
/// A major HTTP protocol version.
|
2019-12-02 12:33:11 +01:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
2021-01-06 19:58:24 +01:00
|
|
|
#[non_exhaustive]
|
2019-12-02 12:33:11 +01:00
|
|
|
pub enum Protocol {
|
|
|
|
Http1,
|
|
|
|
Http2,
|
2021-01-06 19:58:24 +01:00
|
|
|
Http3,
|
2019-12-02 12:33:11 +01:00
|
|
|
}
|
2020-10-30 03:03:26 +01:00
|
|
|
|
|
|
|
type ConnectCallback<IO> = dyn Fn(&IO, &mut Extensions);
|
2021-01-06 19:43:52 +01:00
|
|
|
|
|
|
|
/// Container for data that extract with ConnectCallback.
|
2021-01-06 19:52:06 +01:00
|
|
|
///
|
|
|
|
/// # Implementation Details
|
|
|
|
/// Uses Option to reduce necessary allocations when merging with request extensions.
|
2021-10-19 02:32:58 +02:00
|
|
|
#[derive(Default)]
|
2021-01-06 19:43:52 +01:00
|
|
|
pub(crate) struct OnConnectData(Option<Extensions>);
|
|
|
|
|
|
|
|
impl OnConnectData {
|
2021-01-06 19:52:06 +01:00
|
|
|
/// Construct by calling the on-connect callback with the underlying transport I/O.
|
2021-12-08 07:01:11 +01:00
|
|
|
pub(crate) fn from_io<T>(io: &T, on_connect_ext: Option<&ConnectCallback<T>>) -> Self {
|
2021-01-06 19:43:52 +01:00
|
|
|
let ext = on_connect_ext.map(|handler| {
|
2021-12-07 18:23:34 +01:00
|
|
|
let mut extensions = Extensions::default();
|
2021-01-06 19:43:52 +01:00
|
|
|
handler(io, &mut extensions);
|
|
|
|
extensions
|
|
|
|
});
|
|
|
|
|
|
|
|
Self(ext)
|
|
|
|
}
|
|
|
|
}
|