This commit is contained in:
parent
f363ed1ff0
commit
ec56fcd876
14
.drone.yml
Normal file
14
.drone.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: default
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: cargo_check
|
||||||
|
image: rust
|
||||||
|
commands:
|
||||||
|
- rustup component add clippy
|
||||||
|
- cargo clippy -- -D warnings
|
||||||
|
- cargo test
|
||||||
|
|
||||||
|
|
1324
Cargo.lock
generated
1324
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "req_responder"
|
name = "req_responder"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
env_logger = "0.9.0"
|
env_logger = "0.11.7"
|
||||||
clap = { version = "3.1.15", features = ["derive", "env"] }
|
clap = { version = "4.5.34", features = ["derive", "env"] }
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
futures = "0.3.21"
|
futures = "0.3.21"
|
||||||
|
27
src/main.rs
27
src/main.rs
@ -1,11 +1,10 @@
|
|||||||
use actix_web::{App, Error, error, HttpRequest, HttpResponse, HttpServer, web};
|
|
||||||
use actix_web::web::Payload;
|
use actix_web::web::Payload;
|
||||||
|
use actix_web::{App, Error, HttpRequest, HttpResponse, HttpServer, error, web};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
|
||||||
const MAX_BODY_SIZE: usize = 262_144; // max payload size is 256k
|
const MAX_BODY_SIZE: usize = 262_144; // max payload size is 256k
|
||||||
|
|
||||||
|
|
||||||
/// Simple HTTP responder
|
/// Simple HTTP responder
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
@ -16,7 +15,9 @@ struct Args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn handler(req: HttpRequest, mut payload: Payload) -> Result<HttpResponse, Error> {
|
async fn handler(req: HttpRequest, mut payload: Payload) -> Result<HttpResponse, Error> {
|
||||||
let mut headers = req.headers().iter()
|
let mut headers = req
|
||||||
|
.headers()
|
||||||
|
.iter()
|
||||||
.map(|h| format!("{}: {}", h.0.as_str(), h.1.to_str().unwrap_or_default()))
|
.map(|h| format!("{}: {}", h.0.as_str(), h.1.to_str().unwrap_or_default()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
headers.sort();
|
headers.sort();
|
||||||
@ -31,7 +32,6 @@ async fn handler(req: HttpRequest, mut payload: Payload) -> Result<HttpResponse,
|
|||||||
body.extend_from_slice(&chunk);
|
body.extend_from_slice(&chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let response = format!(
|
let response = format!(
|
||||||
"Remote Peer: {}\nVerb: {}\nPath: {}\nQuery: {}\n\n=== Headers ===\n{}\n\n=== Body ===\n{}",
|
"Remote Peer: {}\nVerb: {}\nPath: {}\nQuery: {}\n\n=== Headers ===\n{}\n\n=== Body ===\n{}",
|
||||||
req.peer_addr().expect("Missing remote peer address!"),
|
req.peer_addr().expect("Missing remote peer address!"),
|
||||||
@ -42,9 +42,7 @@ async fn handler(req: HttpRequest, mut payload: Payload) -> Result<HttpResponse,
|
|||||||
String::from_utf8_lossy(&body)
|
String::from_utf8_lossy(&body)
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok().content_type("text/plain").body(response))
|
||||||
.content_type("text/plain")
|
|
||||||
.body(response))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
@ -55,11 +53,18 @@ async fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
log::info!("Will listen on {}...", args.listen_address);
|
log::info!("Will listen on {}...", args.listen_address);
|
||||||
|
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| App::new().route("{tail:.*}", web::route().to(handler)))
|
||||||
App::new()
|
|
||||||
.route("{tail:.*}", web::route().to(handler))
|
|
||||||
})
|
|
||||||
.bind(args.listen_address)?
|
.bind(args.listen_address)?
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::Args;
|
||||||
|
#[test]
|
||||||
|
fn verify_cli() {
|
||||||
|
use clap::CommandFactory;
|
||||||
|
Args::command().debug_assert()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user