Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing stuff #7

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading