❇️ You can now actually request different files
parent
290745f6cf
commit
d286adadc9
|
@ -103,7 +103,7 @@ async fn handle_http_response (
|
||||||
if ! watchers.wake_one (Message::HttpResponseResponseStream (body), &req_id)
|
if ! watchers.wake_one (Message::HttpResponseResponseStream (body), &req_id)
|
||||||
{
|
{
|
||||||
println! ("Step 8 (bad thing)");
|
println! ("Step 8 (bad thing)");
|
||||||
return status_reply (StatusCode::BAD_REQUEST, "A bad thing happened.\n");
|
status_reply (StatusCode::BAD_REQUEST, "A bad thing happened.\n")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
println! ("Step 8");
|
println! ("Step 8");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::Infallible,
|
convert::Infallible,
|
||||||
error::Error,
|
error::Error,
|
||||||
|
path::PathBuf,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
@ -18,7 +19,6 @@ use tokio::{
|
||||||
io::AsyncReadExt,
|
io::AsyncReadExt,
|
||||||
sync::mpsc::{
|
sync::mpsc::{
|
||||||
channel,
|
channel,
|
||||||
Receiver,
|
|
||||||
},
|
},
|
||||||
time::delay_for,
|
time::delay_for,
|
||||||
};
|
};
|
||||||
|
@ -70,26 +70,25 @@ async fn main () -> Result <(), Box <dyn Error>> {
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
println! ("Client requested {}", parts.uri);
|
let (req_id, uri) = (parts.id, parts.uri);
|
||||||
|
|
||||||
|
println! ("Client requested {}", uri);
|
||||||
|
|
||||||
println! ("Step 4/5");
|
println! ("Step 4/5");
|
||||||
|
|
||||||
println! ("Step 6");
|
println! ("Step 6");
|
||||||
let client = client.clone ();
|
let client = client.clone ();
|
||||||
tokio::spawn (async move {
|
tokio::spawn (async move {
|
||||||
let resp_req = Uri::builder ()
|
|
||||||
.scheme ("http")
|
|
||||||
.authority ("127.0.0.1:4000")
|
|
||||||
.path_and_query ("/listen/alien_wildlands")
|
|
||||||
.build ().unwrap ();
|
|
||||||
|
|
||||||
let (tx, rx) = channel (2);
|
let (tx, rx) = channel (2);
|
||||||
//let rx: Receiver <Vec <u8>> = rx;
|
//let rx: Receiver <Vec <u8>> = rx;
|
||||||
|
|
||||||
tokio::spawn (async move {
|
tokio::spawn (async move {
|
||||||
let path = "/home/user/pictures/bzqcChY.jpg";
|
//let path = "/home/user/projects/2020/ptth/README.md";
|
||||||
let path = "/home/user/videos/Decearing Egg.webm";
|
|
||||||
let path = "/home/user/projects/2020/ptth/README.md";
|
let mut path = PathBuf::from ("/home/user");
|
||||||
|
path.push (&uri [1..]);
|
||||||
|
|
||||||
|
println! ("Opening file {:?}", path);
|
||||||
|
|
||||||
let mut f = File::open (path).await.unwrap ();
|
let mut f = File::open (path).await.unwrap ();
|
||||||
let mut tx = tx;
|
let mut tx = tx;
|
||||||
|
@ -114,14 +113,11 @@ async fn main () -> Result <(), Box <dyn Error>> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let resp_req = client.post (&format! ("http://127.0.0.1:4000/http_response/{}", parts.id)).body (Body::wrap_stream (rx));
|
let resp_req = client.post (&format! ("http://127.0.0.1:4000/http_response/{}", req_id)).body (Body::wrap_stream (rx));
|
||||||
|
|
||||||
println! ("Step 6");
|
println! ("Step 6");
|
||||||
match resp_req.send ().await {
|
if let Err (e) = resp_req.send ().await {
|
||||||
Err (e) => {
|
|
||||||
println! ("Err: {:?}", e);
|
println! ("Err: {:?}", e);
|
||||||
},
|
|
||||||
Ok (_) => (),
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::*,
|
collections::*,
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom},
|
||||||
iter::FromIterator,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
Loading…
Reference in New Issue