-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vertigo-cli: Don't panic when missing root html element
- Loading branch information
Showing
7 changed files
with
53 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
pub async fn is_http_server_listening(port: u16) -> bool { | ||
pub async fn is_http_server_listening(port: u16) -> Result<(), ()> { | ||
use tokio::net::TcpStream; | ||
use tokio::io::AsyncWriteExt; | ||
use tokio::io::AsyncReadExt; | ||
|
||
match TcpStream::connect(("127.0.0.1", port)).await { | ||
Ok(mut stream) => { | ||
// Send a HEAD request to the HTTP server | ||
if stream.write_all(b"HEAD / HTTP/1.0\r\n\r\n").await.is_err() { | ||
return false; | ||
match stream.write_all(b"HEAD / HTTP/1.0\r\n\r\n").await { | ||
Ok(_) => {}, | ||
Err(err) => { | ||
// Network error while sending request | ||
println!("Error = {err}"); | ||
return Err(()); | ||
} | ||
} | ||
|
||
// Wait for a response | ||
let mut buf = [0; 1024]; | ||
match stream.read(&mut buf).await { | ||
Ok(n) if n > 0 => true, // If we received a response, the HTTP server is running | ||
_ => false, // Otherwise, the HTTP server is not running | ||
Ok(n) if n > 0 => { | ||
// If we received a response, the HTTP server is running | ||
Ok(()) | ||
}, | ||
Ok(_) => { | ||
// HTTP server is running but probably failed to configure properly | ||
Err(()) | ||
}, | ||
Err(err) => { | ||
// Network error while reading response | ||
println!("Error = {err}"); | ||
Err(()) | ||
}, | ||
} | ||
}, | ||
Err(_) => false, // Connection error means that the HTTP server is not running | ||
Err(err) => { | ||
// Http server has not opened the socket yet | ||
println!("Error = {err}"); | ||
Err(()) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters