1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-12-04 20:31:55 +01:00
actix-web/actix-http/src/lib.rs

100 lines
2.9 KiB
Rust
Raw Normal View History

2020-10-30 03:19:56 +01:00
//! HTTP primitives for the Actix ecosystem.
2021-02-13 16:08:43 +01:00
//!
//! ## Crate Features
//! | 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-08-13 19:49:58 +02:00
#![deny(rust_2018_idioms, nonstandard_style, clippy::uninit_assumed_init)]
#![allow(
clippy::type_complexity,
clippy::too_many_arguments,
clippy::new_without_default,
2019-12-13 05:59:02 +01:00
clippy::borrow_interior_mutable_const
)]
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;
#[cfg(feature = "__compress")]
2019-03-26 23:14:32 +01:00
pub mod encoding;
2019-03-26 19:54:35 +01:00
mod extensions;
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;
pub use self::header::ContentEncoding;
2021-02-11 23:58:35 +01:00
pub use self::http_message::HttpMessage;
pub use self::message::ConnectionType;
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;
pub use self::response::Response;
pub use self::response_builder::ResponseBuilder;
pub use self::service::HttpService;
2019-03-26 19:54:35 +01: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
}
type ConnectCallback<IO> = dyn Fn(&IO, &mut Extensions);
/// 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)]
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 {
let ext = on_connect_ext.map(|handler| {
let mut extensions = Extensions::default();
handler(io, &mut extensions);
extensions
});
Self(ext)
}
}