@@ -4,7 +4,6 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
44use tokio:: net:: TcpListener ;
55use microhttp_rs:: { parse_request, ParserError } ;
66use log:: { info, error, debug} ;
7- use env_logger;
87
98#[ tokio:: main]
109async fn main ( ) -> std:: io:: Result < ( ) > {
@@ -17,7 +16,7 @@ async fn main() -> std::io::Result<()> {
1716 loop {
1817 // Accept incoming connections
1918 let ( mut socket, addr) = listener. accept ( ) . await ?;
20- info ! ( "Connection from: {}" , addr ) ;
19+ info ! ( "Connection from: {addr}" ) ;
2120
2221 // Spawn a new task for each connection
2322 tokio:: spawn ( async move {
@@ -26,7 +25,7 @@ async fn main() -> std::io::Result<()> {
2625 // Read data from the socket
2726 match socket. read ( & mut buf) . await {
2827 Ok ( n) if n > 0 => {
29- debug ! ( "Received {} bytes" , n ) ;
28+ debug ! ( "Received {n } bytes" ) ;
3029
3130 // Parse the HTTP request
3231 let response = match parse_request ( & buf[ ..n] ) {
@@ -50,18 +49,18 @@ async fn main() -> std::io::Result<()> {
5049 )
5150 } ,
5251 Err ( err) => {
53- error ! ( "Error parsing request: {}" , err ) ;
52+ error ! ( "Error parsing request: {err}" ) ;
5453
5554 // Generate an error response
5655 let error_message = match err {
5756 ParserError :: InvalidPath => "Invalid HTTP path" . to_string ( ) ,
58- ParserError :: MissingHeader ( header) => format ! ( "Required header is missing: {}" , header ) ,
57+ ParserError :: MissingHeader ( header) => format ! ( "Required header is missing: {header}" ) ,
5958 ParserError :: InvalidHeaderFormat => "Invalid header format" . to_string ( ) ,
60- ParserError :: InvalidMethod ( method) => format ! ( "Invalid HTTP method: {}" , method ) ,
61- ParserError :: InvalidVersion ( version) => format ! ( "Invalid HTTP version: {}" , version ) ,
62- ParserError :: MalformedRequestLine ( line) => format ! ( "Malformed request line: {}" , line ) ,
59+ ParserError :: InvalidMethod ( method) => format ! ( "Invalid HTTP method: {method}" ) ,
60+ ParserError :: InvalidVersion ( version) => format ! ( "Invalid HTTP version: {version}" ) ,
61+ ParserError :: MalformedRequestLine ( line) => format ! ( "Malformed request line: {line}" ) ,
6362 ParserError :: EmptyRequest => "Empty request" . to_string ( ) ,
64- ParserError :: JsonError ( e) => format ! ( "JSON parsing error: {}" , e ) ,
63+ ParserError :: JsonError ( e) => format ! ( "JSON parsing error: {e}" ) ,
6564 } ;
6665
6766 format ! (
@@ -78,14 +77,14 @@ async fn main() -> std::io::Result<()> {
7877
7978 // Write the response back to the client
8079 if let Err ( e) = socket. write_all ( response. as_bytes ( ) ) . await {
81- error ! ( "Error writing response: {}" , e ) ;
80+ error ! ( "Error writing response: {e}" ) ;
8281 }
8382 } ,
8483 Ok ( _) => {
8584 info ! ( "Client closed connection" ) ;
8685 } ,
8786 Err ( e) => {
88- error ! ( "Error reading from socket: {}" , e ) ;
87+ error ! ( "Error reading from socket: {e}" ) ;
8988 }
9089 }
9190 } ) ;
0 commit comments