Skip to content
Snippets Groups Projects
Commit 1bb3e76a authored by Stephen D's avatar Stephen D
Browse files

initial commit

parents
Branches master
No related tags found
No related merge requests found
/target
.idea
This diff is collapsed.
[package]
name = "http_echoserver"
version = "0.1.0"
authors = ["Stephen"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
warp = "0.2"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "0.2", features = ["macros"] }
tab_spaces = 4
hard_tabs = true
\ No newline at end of file
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use warp::http::HeaderMap;
use warp::Filter;
#[derive(Serialize, Deserialize)]
struct ResponseBody {
headers: HashMap<String, String>,
}
#[tokio::main]
async fn main() {
let get_req = warp::path!("get")
.and(warp::header::headers_cloned())
.and_then(get_fn);
warp::serve(get_req).run(([127, 0, 0, 1], 3030)).await;
}
async fn get_fn(headers: HeaderMap) -> Result<impl warp::Reply, warp::Rejection> {
let headers: HashMap<String, String> = headers
.iter()
.map(|(name, value)| (name.to_string(), value.to_str().unwrap().to_string()))
.collect();
Ok(warp::reply::json(&ResponseBody { headers }))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment