@@ -2,26 +2,27 @@ use http_req::{request::RequestBuilder, tls, uri::Uri};
22use std:: { convert:: TryFrom , net:: TcpStream } ;
33
44fn main ( ) {
5- //Parse uri and assign it to variable `addr`
6- let addr: Uri = Uri :: try_from ( "https://doc .rust-lang.org/" ) . unwrap ( ) ;
5+ //Parses a URI and assigns it to a variable `addr`.
6+ let addr: Uri = Uri :: try_from ( "https://www .rust-lang.org/learn " ) . unwrap ( ) ;
77
8- //Connect to remote host
8+ //Connects to a remote host. Uses information from `addr`.
99 let stream = TcpStream :: connect ( ( addr. host ( ) . unwrap ( ) , addr. corr_port ( ) ) ) . unwrap ( ) ;
1010
11- //Open secure connection over TlsStream, because of `addr` (https)
11+ //Opens a secure connection over TlsStream. This is required due to use of `https` protocol.
1212 let mut stream = tls:: Config :: default ( )
1313 . connect ( addr. host ( ) . unwrap_or ( "" ) , stream)
1414 . unwrap ( ) ;
1515
16- //Container for response's body
16+ //Container for a response's body.
1717 let mut writer = Vec :: new ( ) ;
1818
19- //Add header `Connection: Close`
19+ //Adds a header `Connection: Close`.
2020 let response = RequestBuilder :: new ( & addr)
2121 . header ( "Connection" , "Close" )
2222 . send ( & mut stream, & mut writer)
2323 . unwrap ( ) ;
2424
2525 println ! ( "Status: {} {}" , response. status_code( ) , response. reason( ) ) ;
26+ println ! ( "Headers: {}" , response. headers( ) ) ;
2627 //println!("{}", String::from_utf8_lossy(&writer));
2728}
0 commit comments