actix_web/
dev.rs

1//! Lower-level types and re-exports.
2//!
3//! Most users will not have to interact with the types in this module, but it is useful for those
4//! writing extractors, middleware, libraries, or interacting with the service API directly.
5//!
6//! # Request Extractors
7//! - [`ConnectionInfo`]: Connection information
8//! - [`PeerAddr`]: Connection information
9
10#[cfg(feature = "__compress")]
11pub use actix_http::encoding::Decoder as Decompress;
12pub use actix_http::{Extensions, Payload, RequestHead, Response, ResponseHead};
13use actix_router::Patterns;
14pub use actix_router::{Path, ResourceDef, ResourcePath, Url};
15pub use actix_server::{Server, ServerHandle};
16pub use actix_service::{
17    always_ready, fn_factory, fn_service, forward_ready, Service, ServiceFactory, Transform,
18};
19
20#[doc(hidden)]
21pub use crate::handler::Handler;
22pub use crate::{
23    config::{AppConfig, AppService},
24    info::{ConnectionInfo, PeerAddr},
25    rmap::ResourceMap,
26    service::{HttpServiceFactory, ServiceRequest, ServiceResponse, WebService},
27    types::{JsonBody, Readlines, UrlEncoded},
28};
29
30pub(crate) fn ensure_leading_slash(mut patterns: Patterns) -> Patterns {
31    match &mut patterns {
32        Patterns::Single(pat) => {
33            if !pat.is_empty() && !pat.starts_with('/') {
34                pat.insert(0, '/');
35            };
36        }
37        Patterns::List(pats) => {
38            for pat in pats {
39                if !pat.is_empty() && !pat.starts_with('/') {
40                    pat.insert(0, '/');
41                };
42            }
43        }
44    }
45
46    patterns
47}