Fix up the output and release a new version.
This commit is contained in:
parent
3c34cc05b9
commit
fbcb0e4562
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "mirror-server"
|
name = "mirror-server"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Dorian Pula <dorian.pula@amber-penguin-software.ca>"]
|
authors = ["Dorian Pula <dorian.pula@amber-penguin-software.ca>"]
|
||||||
description = "A simple server for mirror HTTP requests for testing."
|
description = "A simple server for mirror HTTP requests for testing."
|
||||||
|
@ -17,4 +17,5 @@ section = "web"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
|
clap = { version = "4.0", features = ["derive"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
|
@ -12,3 +12,10 @@ A simple server for mirroring HTTP requests for testing.
|
||||||
* Install cargo-deb: `cargo install cargo-deb`
|
* Install cargo-deb: `cargo install cargo-deb`
|
||||||
* Create the DEB package: `cargo deb`
|
* Create the DEB package: `cargo deb`
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
Download the DEB file, and install it:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl https://code.birch-tree.net/api/packages/dorian/generic/mirror-server/0.2.0/mirror-server_0.2.0_amd64.deb && sudo dpkg -i mirror-server-0.2.0_amd64.deb
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
read -r -p "Username: " USERNAME
|
||||||
|
read -r -s -p "Password: " PASSWORD
|
||||||
|
|
||||||
|
_pkg_name=mirror-server
|
||||||
|
_pkg_version=0.2.0
|
||||||
|
_deb_file="${_pkg_name}_${_pkg_version}_amd64.deb"
|
||||||
|
_deb_path="target/debian"
|
||||||
|
_gitea_server="code.birch-tree.net"
|
||||||
|
|
||||||
|
if [[ ! -f "${_deb_path}/${_deb_file}" ]];
|
||||||
|
then
|
||||||
|
echo "Run cargo deb first!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
curl --user "${USERNAME}:${PASSWORD}" \
|
||||||
|
--upload-file "${_deb_path}/${_deb_file}" \
|
||||||
|
-X PUT \
|
||||||
|
"https://${_gitea_server}/api/packages/${USERNAME}/generic/${_pkg_name}/${_pkg_version}/${_deb_file}"
|
||||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -1,5 +1,19 @@
|
||||||
use actix_web::{web::Json, App, HttpRequest, HttpServer, Responder};
|
use actix_web::{web::Json, App, HttpRequest, HttpServer, Responder};
|
||||||
|
use clap::Parser;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[command(author, version, about, long_about = None)]
|
||||||
|
struct CliArgs {
|
||||||
|
/// Port to run on.
|
||||||
|
#[arg(short, long, default_value_t = 8080)]
|
||||||
|
port: u16,
|
||||||
|
|
||||||
|
/// Listen to IP mask
|
||||||
|
#[arg(short, long, default_value = "0.0.0.0")]
|
||||||
|
ips: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct EchoHeader {
|
struct EchoHeader {
|
||||||
|
@ -12,20 +26,19 @@ struct EchoResponse {
|
||||||
method: String,
|
method: String,
|
||||||
path: String,
|
path: String,
|
||||||
host: String,
|
host: String,
|
||||||
headers: Vec<EchoHeader>,
|
headers: BTreeMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EchoResponse {
|
impl EchoResponse {
|
||||||
fn new(req: &HttpRequest) -> Self {
|
fn new(req: &HttpRequest) -> Self {
|
||||||
let req_uri = req.uri();
|
let req_uri = req.uri();
|
||||||
let headers = req
|
let mut headers = BTreeMap::new();
|
||||||
.headers()
|
for (header_name, header_value) in req.headers().iter() {
|
||||||
.iter()
|
headers.insert(
|
||||||
.map(|(header_name, header_value)| EchoHeader {
|
header_name.to_string(),
|
||||||
name: header_name.to_string(),
|
header_value.to_str().unwrap_or("ERROR").to_string(),
|
||||||
value: header_value.to_str().unwrap_or("ERROR").to_string(),
|
);
|
||||||
})
|
}
|
||||||
.collect::<Vec<EchoHeader>>();
|
|
||||||
EchoResponse {
|
EchoResponse {
|
||||||
method: req.method().to_string(),
|
method: req.method().to_string(),
|
||||||
path: req_uri.path().to_string(),
|
path: req_uri.path().to_string(),
|
||||||
|
@ -42,8 +55,10 @@ async fn echo_request(request: HttpRequest) -> actix_web::Result<impl Responder>
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
|
let cli_args = CliArgs::parse();
|
||||||
|
let listen_on = (cli_args.ips, cli_args.port);
|
||||||
HttpServer::new(|| App::new().default_service(actix_web::web::route().to(echo_request)))
|
HttpServer::new(|| App::new().default_service(actix_web::web::route().to(echo_request)))
|
||||||
.bind(("0.0.0.0", 8080))?
|
.bind(listen_on)?
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue