First response

This commit is contained in:
maxstrb 2025-10-12 21:12:15 +02:00
parent 9a2a500eb0
commit 80fabcde47
4 changed files with 382 additions and 58 deletions

View file

@ -7,7 +7,10 @@ use std::{
net::TcpListener,
};
use crate::request::RequestHeader;
use crate::{
response::{Response, ResponseCode, ResponseHeader},
shared_enums::Content,
};
fn main() -> std::io::Result<()> {
let listener = TcpListener::bind("127.0.0.1:8080")?;
@ -22,7 +25,13 @@ fn main() -> std::io::Result<()> {
let mut writer = stream;
writer.write_all("Ok".as_bytes())?;
let response = Response::new()
.with_code(ResponseCode::Ok)
.with_data(b"<!doctype html><html lang=\"en\"><head><meta charset=\"UTF-8\"/><title>Hello World!</title></head><body><h1>Ahojky</h1><p>Jou jou jou</p></body></html>".to_vec())
.with_header(ResponseHeader::ContentType(Content::html_utf8()));
response.respond(&mut writer)?;
writer.flush()?;
}
Ok(())