❇️ 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)
|
||||
{
|
||||
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 {
|
||||
println! ("Step 8");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::{
|
||||
convert::Infallible,
|
||||
error::Error,
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
@ -18,7 +19,6 @@ use tokio::{
|
|||
io::AsyncReadExt,
|
||||
sync::mpsc::{
|
||||
channel,
|
||||
Receiver,
|
||||
},
|
||||
time::delay_for,
|
||||
};
|
||||
|
@ -70,26 +70,25 @@ async fn main () -> Result <(), Box <dyn Error>> {
|
|||
_ => continue,
|
||||
};
|
||||
|
||||
println! ("Client requested {}", parts.uri);
|
||||
let (req_id, uri) = (parts.id, parts.uri);
|
||||
|
||||
println! ("Client requested {}", uri);
|
||||
|
||||
println! ("Step 4/5");
|
||||
|
||||
println! ("Step 6");
|
||||
let client = client.clone ();
|
||||
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 rx: Receiver <Vec <u8>> = rx;
|
||||
|
||||
tokio::spawn (async move {
|
||||
let path = "/home/user/pictures/bzqcChY.jpg";
|
||||
let path = "/home/user/videos/Decearing Egg.webm";
|
||||
let path = "/home/user/projects/2020/ptth/README.md";
|
||||
//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 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");
|
||||
match resp_req.send ().await {
|
||||
Err (e) => {
|
||||
println! ("Err: {:?}", e);
|
||||
},
|
||||
Ok (_) => (),
|
||||
if let Err (e) = resp_req.send ().await {
|
||||
println! ("Err: {:?}", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::{
|
||||
collections::*,
|
||||
convert::{TryFrom, TryInto},
|
||||
iter::FromIterator,
|
||||
convert::{TryFrom},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
Loading…
Reference in New Issue