1mod config;
7#[cfg(feature = "compress")]
8pub mod encoding;
9pub(crate) mod helpers;
10mod httpcodes;
11mod httpmessage;
12pub(crate) mod json;
13mod message;
14mod payload;
15mod request;
16mod response;
17mod service;
18
19pub mod error;
20pub mod h1;
21pub mod h2;
22pub mod test;
23
24pub(crate) use self::message::{CurrentIo, IoAccess, Message};
25
26pub use self::config::{DateService, HttpServiceConfig, KeepAlive};
27pub use self::error::ResponseError;
28pub use self::httpmessage::HttpMessage;
29pub use self::message::{ConnectionType, RequestHead, ResponseHead};
30pub use self::payload::{Payload, PayloadStream};
31pub use self::request::Request;
32pub use self::response::{Response, ResponseBuilder};
33pub use self::service::HttpService;
34pub use crate::io::types::HttpProtocol;
35
36pub use ntex_http::{HeaderMap, Method, StatusCode, Version, body, header};
38
39pub const ALPN_PROTO_H1: &[&str] = &["http/1.1"];
41pub const ALPN_PROTO_H2: &[&str] = &["h2"];
43pub const ALPN_PROTOS: &[&str] = &["h2", "http/1.1"];
45
46#[derive(Clone, PartialEq, Eq, Debug)]
48pub struct HeaderItem {
49 pub name: header::HeaderName,
51 pub origin: crate::util::ByteString,
53 pub value: header::HeaderValue,
55}
56
57#[cfg(feature = "openssl")]
58use crate::server::openssl::{SslAcceptor, SslFilter};
59#[cfg(any(feature = "openssl", feature = "rustls"))]
60use crate::{IntoService, Service, io::Filter, io::Io, io::Layer, server::TlsError};
61
62#[cfg(feature = "openssl")]
63pub fn openssl<F, S, St>(
70 acceptor: tls_openssl::ssl::SslAcceptor,
71 service: impl IntoService<S, St, Io<Layer<SslFilter, F>>>,
72) -> impl Service<St, Io<F>, Res = S::Res, Error = TlsError<S::Error>>
73where
74 F: Filter,
75 S: Service<St, Io<Layer<SslFilter, F>>>,
76{
77 SslAcceptor::new(acceptor)
78 .map_err(TlsError::Tls)
79 .and_then(service.into_service().map_err(TlsError::Service))
80}
81
82#[cfg(feature = "rustls")]
83use crate::server::rustls::{TlsAcceptor, TlsServerFilter};
84
85#[cfg(feature = "rustls")]
86pub fn rustls<F, S, St>(
93 mut config: tls_rustls::ServerConfig,
94 protos: &[&str],
95 service: impl IntoService<S, St, Io<Layer<TlsServerFilter, F>>>,
96) -> impl Service<St, Io<F>, Res = S::Res, Error = TlsError<S::Error>>
97where
98 F: Filter,
99 S: Service<St, Io<Layer<TlsServerFilter, F>>>,
100{
101 if !protos.is_empty() && config.alpn_protocols.is_empty() {
102 config.alpn_protocols = protos.iter().map(|s| s.to_string().into()).collect();
103 }
104
105 TlsAcceptor::new(std::sync::Arc::new(config))
106 .map_err(TlsError::Tls)
107 .and_then(service.into_service().map_err(TlsError::Service))
108}
109
110use crate::error::Error;
111use crate::service::pipeline::PipelineFactory;
112
113type HttpPipeline<St, Err> = PipelineFactory<St, Request, Response, Err, error::DispatchError>;
114type Ctl1Pipeline<St, F, Err> = PipelineFactory<
115 St,
116 h1::Control<F, Err>,
117 h1::ControlAck<F>,
118 error::DispatchError,
119 error::DispatchError,
120>;
121type Ctl2Pipeline<St> = PipelineFactory<
122 St,
123 h2::Control<Error<error::H2Error>>,
124 h2::ControlAck,
125 error::DispatchError,
126 error::DispatchError,
127>;