mini https

This commit is contained in:
Christoph J. Scherr 2024-01-24 10:56:55 +01:00
parent c240551ad5
commit 5ff6987a07
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
1 changed files with 14 additions and 6 deletions

View File

@ -73,7 +73,7 @@ impl Server {
let (stream, addr) = match rc_self.server.accept().await { let (stream, addr) = match rc_self.server.accept().await {
Ok(s) => s, Ok(s) => s,
Err(err) => { Err(err) => {
warn!("could not accept stream: {err:?}"); warn!("could not accept tcp stream: {err:?}");
continue; continue;
} }
}; };
@ -86,7 +86,7 @@ impl Server {
match ref_self.acceptor.accept(stream).await { match ref_self.acceptor.accept(stream).await {
Ok(s) => s, Ok(s) => s,
Err(err) => { Err(err) => {
error!("could not accept tcp stream: {err}"); warn!("could not accept tls stream: {err}");
return; return;
} }
}; };
@ -150,12 +150,20 @@ impl Server {
addr: SocketAddr, addr: SocketAddr,
) -> Result<()> { ) -> Result<()> {
debug!("new peer: {:?}", addr); debug!("new peer: {:?}", addr);
let mut buf = [0; BUF_SIZE]; loop {
while stream.read(&mut buf).await? != 0 { stream
stream.write_all(b"pong\0"); .write_all(
&b"HTTP/1.0 200 ok\r\n\
Connection: close\r\n\
Content-length: 12\r\n\
\r\n\
Hello world!"[..],
)
.await?;
stream.flush().await?;
// we should wait, so that we don't spam the client // we should wait, so that we don't spam the client
std::thread::sleep(self.cfg.delay); std::thread::sleep(self.cfg.delay);
break;
} }
debug!("disconnected peer: {:?}", addr); debug!("disconnected peer: {:?}", addr);
Ok(()) Ok(())