mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
latest revised test
This commit is contained in:
parent
4463b909a1
commit
140f07ddc8
1 changed files with 28 additions and 34 deletions
|
|
@ -73,43 +73,37 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
|
|||
if let Some(url) = tokens.next() {
|
||||
match url.split_once('/') {
|
||||
Some((host, path)) => {
|
||||
match self.dns.lookup(host) {
|
||||
Ok(ipaddr) => {
|
||||
log::info!("resolved {} to {:?}", host, ipaddr);
|
||||
match TcpStream::connect((IpAddr::from(ipaddr), 80)) {
|
||||
Ok(mut stream) => {
|
||||
log::trace!("stream open, setting timeouts");
|
||||
stream.set_read_timeout(Some(std::time::Duration::from_millis(10_000))).unwrap();
|
||||
stream.set_write_timeout(Some(std::time::Duration::from_millis(10_000))).unwrap();
|
||||
log::debug!("read timeout: {:?}", stream.read_timeout().unwrap().unwrap().as_millis());
|
||||
log::debug!("write timeout: {:?}", stream.write_timeout().unwrap().unwrap().as_millis());
|
||||
log::info!("my socket: {:?}", stream.local_addr());
|
||||
log::info!("peer addr: {:?}", stream.peer_addr());
|
||||
log::info!("sending GET request");
|
||||
match write!(stream, "GET /{} HTTP/1.1\r\n", path) {
|
||||
Ok(_) => log::trace!("sent GET"),
|
||||
Err(e) => {
|
||||
log::error!("GET err {:?}", e);
|
||||
write!(ret, "Error sending GET: {:?}", e).unwrap();
|
||||
}
|
||||
}
|
||||
write!(stream, "Host: {}\r\nAccept: */*\r\nUser-Agent: Precursor/0.9.6\r\n", host).expect("stream error");
|
||||
write!(stream, "Connection: close\r\n").expect("stream error");
|
||||
write!(stream, "\r\n").expect("stream error");
|
||||
log::info!("fetching response....");
|
||||
let mut buf = [0u8; 512];
|
||||
match stream.read(&mut buf) {
|
||||
Ok(len) => {
|
||||
log::trace!("raw response ({}): {:?}", len, &buf[..len]);
|
||||
write!(ret, "{}", std::string::String::from_utf8_lossy(&buf[..len])).unwrap();
|
||||
}
|
||||
Err(e) => write!(ret, "Didn't get response from host: {:?}", e).unwrap(),
|
||||
}
|
||||
match TcpStream::connect((host, 80)) {
|
||||
Ok(mut stream) => {
|
||||
log::trace!("stream open, setting timeouts");
|
||||
stream.set_read_timeout(Some(std::time::Duration::from_millis(10_000))).unwrap();
|
||||
stream.set_write_timeout(Some(std::time::Duration::from_millis(10_000))).unwrap();
|
||||
log::debug!("read timeout: {:?}", stream.read_timeout().unwrap().unwrap().as_millis());
|
||||
log::debug!("write timeout: {:?}", stream.write_timeout().unwrap().unwrap().as_millis());
|
||||
log::info!("my socket: {:?}", stream.local_addr());
|
||||
log::info!("peer addr: {:?}", stream.peer_addr());
|
||||
log::info!("sending GET request");
|
||||
match write!(stream, "GET /{} HTTP/1.1\r\n", path) {
|
||||
Ok(_) => log::trace!("sent GET"),
|
||||
Err(e) => {
|
||||
log::error!("GET err {:?}", e);
|
||||
write!(ret, "Error sending GET: {:?}", e).unwrap();
|
||||
}
|
||||
Err(e) => write!(ret, "Couldn't connect to {}:80: {:?}", host, e).unwrap(),
|
||||
}
|
||||
write!(stream, "Host: {}\r\nAccept: */*\r\nUser-Agent: Precursor/0.9.6\r\n", host).expect("stream error");
|
||||
write!(stream, "Connection: close\r\n").expect("stream error");
|
||||
write!(stream, "\r\n").expect("stream error");
|
||||
log::info!("fetching response....");
|
||||
let mut buf = [0u8; 512];
|
||||
match stream.read(&mut buf) {
|
||||
Ok(len) => {
|
||||
log::trace!("raw response ({}): {:?}", len, &buf[..len]);
|
||||
write!(ret, "{}", std::string::String::from_utf8_lossy(&buf[..len])).unwrap();
|
||||
}
|
||||
Err(e) => write!(ret, "Didn't get response from host: {:?}", e).unwrap(),
|
||||
}
|
||||
}
|
||||
_ => write!(ret, "Couldn't resolve {}", host).unwrap(),
|
||||
Err(e) => write!(ret, "Couldn't connect to {}:80: {:?}", host, e).unwrap(),
|
||||
}
|
||||
}
|
||||
_ => write!(ret, "Usage: tcpget bunniefoo.com/bunnie/test.txt").unwrap(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue