Skip to content

Commit

Permalink
tmp add test server
Browse files Browse the repository at this point in the history
  • Loading branch information
Akida31 committed Jan 26, 2023
1 parent 8c25e01 commit 179d8d3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
13 changes: 13 additions & 0 deletions TEST/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]}
21 changes: 21 additions & 0 deletions TEST/client.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions TEST/server.py
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 23 additions & 0 deletions TEST/src/main.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 179d8d3

Please sign in to comment.