From 179d8d3cfde27271fcc8786c8bc15b0cfb9dcd50 Mon Sep 17 00:00:00 2001 From: akida31 Date: Thu, 26 Jan 2023 15:08:15 +0100 Subject: [PATCH] tmp add test server --- TEST/Cargo.toml | 13 +++++++++++++ TEST/client.py | 21 +++++++++++++++++++++ TEST/server.py | 11 +++++++++++ TEST/src/main.rs | 23 +++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 TEST/Cargo.toml create mode 100644 TEST/client.py create mode 100644 TEST/server.py create mode 100644 TEST/src/main.rs diff --git a/TEST/Cargo.toml b/TEST/Cargo.toml new file mode 100644 index 00000000000..c1c6a38b1c9 --- /dev/null +++ b/TEST/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "server" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +axum = "0.6.4" +tokio = {version = "1.24.2", features = ["full"]} +tower-http = {version = "0.3.5", features = ["trace", "tracing"]} +tracing = "0.1.37" +tracing-subscriber = {version = "0.3.16", features = ["env-filter"]} diff --git a/TEST/client.py b/TEST/client.py new file mode 100644 index 00000000000..0d5c624298a --- /dev/null +++ b/TEST/client.py @@ -0,0 +1,21 @@ +import requests + +def test(n): + header = b"foo" + int.to_bytes(n, 1, "little") + url = "http://localhost:5000" + #url = "https://crates.io" + try: + headers = {"Authorization": header} + r = requests.get(url, headers=headers) + print("Header:", header, "Response:", r.status_code) + return r.status_code == 200 + except ValueError as e: + print("Header:", header, "Request error:", e) + return False + +invalid = [] +for i in range(256): + if not test(i): + invalid.append(i) + +print("invalid:", invalid) diff --git a/TEST/server.py b/TEST/server.py new file mode 100644 index 00000000000..32b7f58d5d0 --- /dev/null +++ b/TEST/server.py @@ -0,0 +1,11 @@ +from flask import request, Flask + +app = Flask(__name__) + +@app.route('/') +def home(): + h = request.headers + print(h) + return "Hi" + +app.run() diff --git a/TEST/src/main.rs b/TEST/src/main.rs new file mode 100644 index 00000000000..5c9eabeb24d --- /dev/null +++ b/TEST/src/main.rs @@ -0,0 +1,23 @@ +use axum::{http::header::HeaderMap, routing::get, Router}; + +async fn home(headers: HeaderMap) -> &'static str { + dbg!(headers); + "Hello World" +} + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt() + .with_max_level(tracing::Level::TRACE) + .init(); + let app = Router::new() + .route("/", get(home)) + .layer(tower_http::trace::TraceLayer::new_for_http()); + + // run it with hyper on localhost:3000 + tracing::warn!("starting"); + axum::Server::bind(&"0.0.0.0:5000".parse().unwrap()) + .serve(app.into_make_service()) + .await + .unwrap(); +}