Skip to main content

axum/extract/
mod.rs

1#![doc = include_str!("../docs/extract.md")]
2
3use http::header::{self, HeaderMap};
4
5#[cfg(feature = "tokio")]
6pub mod connect_info;
7pub mod path;
8pub mod rejection;
9
10#[cfg(feature = "ws")]
11pub mod ws;
12
13pub(crate) mod nested_path;
14#[cfg(feature = "original-uri")]
15mod original_uri;
16mod raw_form;
17mod raw_query;
18mod state;
19
20#[doc(inline)]
21pub use axum_core::extract::{
22    DefaultBodyLimit, FromRef, FromRequest, FromRequestParts, OptionalFromRequest,
23    OptionalFromRequestParts, Request,
24};
25
26#[cfg(feature = "macros")]
27pub use axum_macros::{FromRef, FromRequest, FromRequestParts};
28
29#[doc(inline)]
30pub use self::{
31    nested_path::NestedPath,
32    path::{Path, RawPathParams},
33    raw_form::RawForm,
34    raw_query::RawQuery,
35    state::State,
36};
37
38#[doc(inline)]
39#[cfg(feature = "tokio")]
40pub use self::connect_info::ConnectInfo;
41
42#[doc(no_inline)]
43#[cfg(feature = "json")]
44pub use crate::Json;
45
46#[doc(no_inline)]
47pub use crate::Extension;
48
49#[cfg(feature = "form")]
50#[doc(no_inline)]
51pub use crate::form::Form;
52
53#[doc(inline)]
54pub use self::path::inner_path::InnerPath;
55
56#[cfg(feature = "matched-path")]
57pub(crate) mod matched_path;
58
59#[cfg(feature = "matched-path")]
60#[doc(inline)]
61pub use self::matched_path::MatchedPath;
62
63#[cfg(feature = "multipart")]
64pub mod multipart;
65
66#[cfg(feature = "multipart")]
67#[doc(inline)]
68pub use self::multipart::Multipart;
69
70#[cfg(feature = "query")]
71mod query;
72
73#[cfg(feature = "query")]
74#[doc(inline)]
75pub use self::query::Query;
76
77#[cfg(feature = "original-uri")]
78#[doc(inline)]
79pub use self::original_uri::OriginalUri;
80
81#[cfg(feature = "ws")]
82#[doc(inline)]
83pub use self::ws::WebSocketUpgrade;
84
85// this is duplicated in `axum-extra/src/extract/form.rs`
86pub(super) fn has_content_type(headers: &HeaderMap, expected_content_type: &mime::Mime) -> bool {
87    let Some(content_type) = headers.get(header::CONTENT_TYPE) else {
88        return false;
89    };
90
91    let Ok(content_type) = content_type.to_str() else {
92        return false;
93    };
94
95    content_type.starts_with(expected_content_type.as_ref())
96}
97
98#[cfg(test)]
99mod tests {
100    use crate::{routing::get, test_helpers::*, Router};
101
102    #[crate::test]
103    async fn consume_body() {
104        let app = Router::new().route("/", get(|body: String| async { body }));
105
106        let client = TestClient::new(app);
107        let res = client.get("/").body("foo").await;
108        let body = res.text().await;
109
110        assert_eq!(body, "foo");
111    }
112}