Skip to main content

ntex/
lib.rs

1//! A framework for composable network services.
2//!
3//! ntex provides a single-threaded service framework, HTTP client and server
4//! implementations, a web application framework, and WebSocket support.
5//!
6//! The most commonly used entry points are:
7//!
8//! - [`web`] for HTTP applications and servers
9//! - [`client`] for outgoing HTTP requests
10//! - [`http`] for lower-level HTTP services and message types
11//! - [`service`](mod@service) for composing services and middleware
12//! - [`ws`] for WebSocket protocol support (enabled by the `ws` feature)
13//!
14//! ## Runtime selection
15//!
16//! ntex uses its native Neon runtime by default. Enable `tokio` or `compio` to
17//! use the corresponding runtime backend. The `neon-polling` and `neon-uring`
18//! features select a specific native I/O reactor, Windows always uses IOCP.
19//!
20//! ## Crate features
21//!
22//! - `tokio` selects the Tokio runtime backend.
23//! - `compio` selects the Compio runtime backend.
24//! - `neon-polling` and `neon-uring` select the Neon runtime with the polling
25//!   reactor on Unix or the io-uring reactor on Linux.
26//! - `ws` (default) enables WebSocket support.
27//! - `openssl` enables TLS support through OpenSSL.
28//! - `rustls` enables TLS support through rustls.
29//! - `compress` enables HTTP content compression and decompression (gzip,
30//!   deflate and zstd).
31//! - `cookie` enables HTTP cookie support.
32//! - `no-test-logging` disables automatic logging configuration in
33//!   [`test`](macro@test).
34//! - `trace` enables additional trace-level logging.
35#![deny(clippy::pedantic)]
36#![allow(
37    type_alias_bounds,
38    missing_debug_implementations,
39    clippy::cast_possible_truncation,
40    clippy::missing_errors_doc,
41    clippy::missing_fields_in_debug,
42    clippy::missing_panics_doc,
43    clippy::must_use_candidate,
44    clippy::too_many_lines,
45    clippy::type_complexity,
46    clippy::unused_async_trait_impl
47)]
48// Used for fake variadics
49#![cfg_attr(any(docsrs, docsrs_dep), feature(rustdoc_internals))]
50
51#[cfg(not(test))] // Work around for rust-lang/rust#62127
52pub use ntex_macros::{rt_main as main, rt_test as test};
53
54#[cfg(test)]
55pub(crate) use ntex_macros::rt_test_internal as rt_test;
56
57pub use ntex_service::{forward_ready, forward_shutdown};
58
59pub mod client;
60pub mod http;
61pub mod web;
62
63#[cfg(feature = "ws")]
64pub mod ws;
65
66pub use urly as url;
67
68pub use self::service::{
69    Ctx, IntoService, IntoServiceFactory, Middleware, Service, ServiceFactory, cfg::Cfg,
70    cfg::SharedCfg, factory, fn_service, pipeline::Pipeline, pipeline::PipelineBinding,
71    pipeline::PipelineFactory, service,
72};
73pub use ntex_error::Error;
74
75pub use ntex_util::{channel, task};
76
77pub mod codec {
78    //! Utilities for encoding and decoding frames.
79    pub use ntex_codec::*;
80}
81
82pub mod connect {
83    //! TCP connector services.
84    pub use ntex_net::connect::*;
85
86    #[cfg(feature = "openssl")]
87    pub mod openssl {
88        //! TLS connector support through OpenSSL.
89        pub use ntex_tls::openssl::*;
90    }
91
92    #[cfg(feature = "rustls")]
93    pub mod rustls {
94        //! TLS connector support through rustls.
95        pub use ntex_tls::rustls::*;
96    }
97}
98
99pub mod router {
100    //! Resource path matching library.
101    pub use ntex_router::*;
102}
103
104pub mod rt {
105    //! Runtime APIs for running tasks on the current thread.
106    pub use ntex_rt::*;
107
108    pub use ntex_net::*;
109}
110
111pub mod service {
112    //! Service, service factory, and middleware abstractions.
113    pub use ntex_service::*;
114}
115
116pub mod server {
117    //! General-purpose TCP server APIs.
118    pub use ntex_server::net::*;
119
120    #[cfg(feature = "openssl")]
121    pub use ntex_tls::openssl;
122
123    #[cfg(feature = "rustls")]
124    pub use ntex_tls::rustls;
125
126    pub use ntex_tls::{TlsConfig, TlsError};
127}
128
129pub mod time {
130    //! Utilities for tracking time.
131    pub use ntex_util::time::*;
132}
133
134pub mod io {
135    //! IO streaming utilities.
136    pub use ntex_dispatcher::*;
137    pub use ntex_io::*;
138}
139
140pub mod testing {
141    //! IO testing utilities.
142    pub use ntex_io::testing::IoTest;
143}
144
145pub mod tls {
146    //! TLS support for ntex ecosystem.
147    pub use ntex_tls::*;
148}
149
150pub mod error {
151    //! Error types and helpers.
152    pub use ntex_error::*;
153}
154
155pub mod util {
156    //! Common byte, collection, future, and service utilities.
157    pub use ntex_bytes::{Buf, BufMut, ByteString, Bytes, BytesMut};
158    pub use ntex_bytes::{BytePage, BytePageSize, BytePages};
159    pub use ntex_error::{ErrorMessage, ErrorMessageChained, fmt_err, fmt_err_string};
160    pub use ntex_util::{
161        Equivalent, HashMap, HashRandomState, HashSet, clone_io_error, dyn_err, dyn_rc_err,
162        future::*, hash_map, hash_set, services::*, str_rc_err,
163    };
164
165    #[doc(hidden)]
166    pub fn enable_test_logging() {
167        #[cfg(not(feature = "no-test-logging"))]
168        if std::env::var("NTEX_NO_TEST_LOG").is_err() {
169            if std::env::var("RUST_LOG").is_err() {
170                unsafe {
171                    std::env::set_var("RUST_LOG", "trace");
172                }
173            }
174            let _ = env_logger::builder().is_test(true).try_init();
175        }
176    }
177}