#6 writing a response
This commit is contained in:
parent
4a29f88e3e
commit
1fc91880d8
1 changed files with 5 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use std::io::Read;
|
use std::io::{Read, Write};
|
||||||
use std::net::{TcpListener, TcpStream};
|
use std::net::{TcpListener, TcpStream};
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
|
|
@ -14,5 +14,9 @@ fn handle_connection(mut stream: TcpStream) -> std::io::Result<()>{
|
||||||
let mut buffer = [0; 1024];
|
let mut buffer = [0; 1024];
|
||||||
stream.read(&mut buffer)?;
|
stream.read(&mut buffer)?;
|
||||||
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
|
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
|
||||||
|
|
||||||
|
let response = "HTTP/1.1 200 OK\r\n\r\n";
|
||||||
|
stream.write(response.as_bytes())?;
|
||||||
|
stream.flush()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue