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 | |
| 3 | use http::header::{self, HeaderMap}; |
| 4 | |
| 5 | #[cfg(feature = "tokio")] |
| 6 | pub mod connect_info; |
| 7 | pub mod path; |
| 8 | pub mod rejection; |
| 9 | |
| 10 | #[cfg(feature = "ws")] |
| 11 | pub mod ws; |
| 12 | |
| 13 | pub(crate) mod nested_path; |
| 14 | #[cfg(feature = "original-uri")] |
| 15 | mod original_uri; |
| 16 | mod raw_form; |
| 17 | mod raw_query; |
| 18 | mod state; |
| 19 | |
| 20 | #[doc(inline)] |
| 21 | pub use axum_core::extract::{ |
| 22 | DefaultBodyLimit, FromRef, FromRequest, FromRequestParts, OptionalFromRequest, |
| 23 | OptionalFromRequestParts, Request, |
| 24 | }; |
| 25 | |
| 26 | #[cfg(feature = "macros")] |
| 27 | pub use axum_macros::{FromRef, FromRequest, FromRequestParts}; |
| 28 | |
| 29 | #[doc(inline)] |
| 30 | pub 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")] |
| 40 | pub use self::connect_info::ConnectInfo; |
| 41 | |
| 42 | #[doc(no_inline)] |
| 43 | #[cfg(feature = "json")] |
| 44 | pub use crate::Json; |
| 45 | |
| 46 | #[doc(no_inline)] |
| 47 | pub use crate::Extension; |
| 48 | |
| 49 | #[cfg(feature = "form")] |
| 50 | #[doc(no_inline)] |
| 51 | pub use crate::form::Form; |
| 52 | |
| 53 | #[cfg(feature = "matched-path")] |
| 54 | pub(crate) mod matched_path; |
| 55 | |
| 56 | #[cfg(feature = "matched-path")] |
| 57 | #[doc(inline)] |
| 58 | pub use self::matched_path::MatchedPath; |
| 59 | |
| 60 | #[cfg(feature = "multipart")] |
| 61 | pub mod multipart; |
| 62 | |
| 63 | #[cfg(feature = "multipart")] |
| 64 | #[doc(inline)] |
| 65 | pub use self::multipart::Multipart; |
| 66 | |
| 67 | #[cfg(feature = "query")] |
| 68 | mod query; |
| 69 | |
| 70 | #[cfg(feature = "query")] |
| 71 | #[doc(inline)] |
| 72 | pub use self::query::Query; |
| 73 | |
| 74 | #[cfg(feature = "original-uri")] |
| 75 | #[doc(inline)] |
| 76 | pub use self::original_uri::OriginalUri; |
| 77 | |
| 78 | #[cfg(feature = "ws")] |
| 79 | #[doc(inline)] |
| 80 | pub use self::ws::WebSocketUpgrade; |
| 81 | |
| 82 | // this is duplicated in `axum-extra/src/extract/form.rs` |
| 83 | pub(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)] |
| 96 | mod 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 | } |