Skip to content

Commit

Permalink
testing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
itrofimow committed Nov 30, 2023
1 parent 3204088 commit 3deca26
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions frameworks/Rust/axum/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{
http::{header, HeaderValue, StatusCode},
http::{header, HeaderMap, HeaderName, HeaderValue, StatusCode},
response::IntoResponse,
routing::get,
Json, Router,
Expand All @@ -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 {
Expand All @@ -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();

Expand Down

0 comments on commit 3deca26

Please sign in to comment.