From 3deca26bd7e7dc352ec559a7b63a9d67e60d77fe Mon Sep 17 00:00:00 2001 From: Ivan Trofimov Date: Thu, 30 Nov 2023 21:43:34 +0300 Subject: [PATCH] testing stuff --- frameworks/Rust/axum/src/main.rs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/frameworks/Rust/axum/src/main.rs b/frameworks/Rust/axum/src/main.rs index 075ee1c01e6..71bd015d796 100644 --- a/frameworks/Rust/axum/src/main.rs +++ b/frameworks/Rust/axum/src/main.rs @@ -1,5 +1,5 @@ use axum::{ - http::{header, HeaderValue, StatusCode}, + http::{header, HeaderMap, HeaderName, HeaderValue, StatusCode}, response::IntoResponse, routing::get, Json, Router, @@ -12,8 +12,28 @@ mod server; use self::models_common::Message; -pub async fn plaintext() -> &'static str { - "Hello, World!" +const CUSTOM_HEADERS: [HeaderName; 3] = [ + HeaderName::from_static("x-my-first-custom-header"), + HeaderName::from_static("x-my-second-custom-header"), + HeaderName::from_static("x-my-third-custom-header"), +]; + +const RESPONSES: [&str; 4] = [ + "Hello, World", + "Hello, World1", + "Hello, World2", + "Hello, World3", +]; + +pub async fn plaintext(headers: HeaderMap) -> &'static str { + let mut count = 0; + for hdr in CUSTOM_HEADERS { + if headers.contains_key(hdr) { + count += 1; + } + } + + RESPONSES[count] } pub async fn json() -> impl IntoResponse { @@ -24,7 +44,8 @@ pub async fn json() -> impl IntoResponse { (StatusCode::OK, Json(message)) } -#[tokio::main] +//#[tokio::main] +#[tokio::main(flavor = "current_thread")] async fn main() { dotenv().ok();