Browse Source

initial commit

master
Stephen 7 months ago
commit
1bb3e76a08
5 changed files with 1352 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +1310
    -0
      Cargo.lock
  3. +12
    -0
      Cargo.toml
  4. +2
    -0
      rustfmt.toml
  5. +26
    -0
      src/main.rs

+ 2
- 0
.gitignore View File

@ -0,0 +1,2 @@
/target
.idea

+ 1310
- 0
Cargo.lock
File diff suppressed because it is too large
View File


+ 12
- 0
Cargo.toml View File

@ -0,0 +1,12 @@
[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"] }

+ 2
- 0
rustfmt.toml View File

@ -0,0 +1,2 @@
tab_spaces = 4
hard_tabs = true

+ 26
- 0
src/main.rs View File

@ -0,0 +1,26 @@
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 }))
}

Loading…
Cancel
Save