72 lines
1.5 KiB
Rust
72 lines
1.5 KiB
Rust
pub mod http_serde;
|
|
|
|
// It's easier if the server can stream its response body
|
|
// back to the relay un-changed inside its request body
|
|
// So we wrap the server's actual response head
|
|
// (status code, headers, etc.) in this one header field.
|
|
|
|
pub const PTTH_MAGIC_HEADER: &str = "X-PTTH-2LJYXWC4";
|
|
|
|
// Basically binaries, but in the lib we can do experimental
|
|
// test stuff like spawn them both in the same process
|
|
|
|
pub mod relay;
|
|
pub mod server;
|
|
|
|
#[cfg (test)]
|
|
mod tests {
|
|
use tokio::{
|
|
runtime::Runtime,
|
|
spawn,
|
|
};
|
|
|
|
use super::{
|
|
relay,
|
|
server,
|
|
};
|
|
|
|
#[test]
|
|
fn end_to_end () {
|
|
use reqwest::Client;
|
|
|
|
let mut rt = Runtime::new ().unwrap ();
|
|
|
|
// Spawn the root task
|
|
rt.block_on (async {
|
|
spawn (async {
|
|
relay::main ().await.unwrap ();
|
|
});
|
|
|
|
spawn (async {
|
|
let opt = server::Opt {
|
|
root: ".".into (),
|
|
};
|
|
|
|
server::main (opt).await.unwrap ();
|
|
});
|
|
|
|
let client = Client::new ();
|
|
|
|
let resp = client.get ("http://127.0.0.1:4000/relay_up_check")
|
|
.send ().await.unwrap ().bytes ().await.unwrap ();
|
|
|
|
assert_eq! (resp, "Relay is up\n");
|
|
|
|
let resp = client.get ("http://127.0.0.1:4000/http_request/alien_wildlands/COPYING")
|
|
.send ().await.unwrap ().bytes ().await.unwrap ();
|
|
|
|
assert_eq! (blake3::hash (&resp), blake3::Hash::from ([
|
|
0xca, 0x02, 0x92, 0x78,
|
|
0x9c, 0x0a, 0x0e, 0xcb,
|
|
0xa7, 0x06, 0xf4, 0xb3,
|
|
0xf3, 0x49, 0x30, 0x07,
|
|
|
|
0xa9, 0x95, 0x17, 0x31,
|
|
0xc1, 0xd4, 0x32, 0xc5,
|
|
0x2c, 0x4a, 0xac, 0x1f,
|
|
0x1a, 0xbb, 0xa8, 0xef,
|
|
]));
|
|
});
|
|
}
|
|
}
|