Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_text/tests/annealer_corpus/axum_extract.rs

2.3 KiB, 1 run

created by r1870400018:11688, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

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#[cfg(feature = "matched-path")]
54pub(crate) mod matched_path;
55
56#[cfg(feature = "matched-path")]
57#[doc(inline)]
58pub use self::matched_path::MatchedPath;
59
60#[cfg(feature = "multipart")]
61pub mod multipart;
62
63#[cfg(feature = "multipart")]
64#[doc(inline)]
65pub use self::multipart::Multipart;
66
67#[cfg(feature = "query")]
68mod query;
69
70#[cfg(feature = "query")]
71#[doc(inline)]
72pub use self::query::Query;
73
74#[cfg(feature = "original-uri")]
75#[doc(inline)]
76pub use self::original_uri::OriginalUri;
77
78#[cfg(feature = "ws")]
79#[doc(inline)]
80pub use self::ws::WebSocketUpgrade;
81
82// this is duplicated in `axum-extra/src/extract/form.rs`
83pub(super) fn has_content_type(headers: &HeaderMap, expected_content_type: &mime::Mime) -> bool {
84 let Some(content_type) = headers.get(header::CONTENT_TYPE) else {
85 return false;
86 };
87
88 let Ok(content_type) = content_type.to_str() else {
89 return false;
90 };
91
92 content_type.starts_with(expected_content_type.as_ref())
93}
94
95#[cfg(test)]
96mod tests {
97 use crate::{routing::get, test_helpers::*, Router};
98
99 #[crate::test]
100 async fn consume_body() {
101 let app = Router::new().route("/", get(|body: String| async { body }));
102
103 let client = TestClient::new(app);
104 let res = client.get("/").body("foo").await;
105 let body = res.text().await;
106
107 assert_eq!(body, "foo");
108 }
109}