refactor: http module

This commit is contained in:
2024-12-01 17:52:50 +01:00
parent 607d14ab62
commit bebf37162f
6 changed files with 86 additions and 75 deletions

36
src/http/types.rs Normal file
View File

@@ -0,0 +1,36 @@
use std::collections::HashMap;
// TODO:
// - we could complement status with a struct that stores the status and the error message.
// - an alternative is to have a status-error_mesage mapper in order to send an error explanation to the client
pub type Status = u16;
pub type Body<'a> = Option<&'a str>;
#[derive(Debug)]
pub struct ProcessedResponse {
pub data: String,
pub status: Status,
}
pub type QueryParams<'a> = HashMap<&'a str, &'a str>;
pub type Headers<'a> = HashMap<&'a str, &'a str>;
#[derive(Debug)]
pub struct HttpRequestQuery<'a> {
pub path: &'a str,
pub params: QueryParams<'a>,
}
#[derive(Debug)]
pub struct HttpRequestLine<'a> {
pub method: &'a str,
pub version: &'a str,
pub query: HttpRequestQuery<'a>,
}
#[derive(Debug)]
pub struct HttpRequest<'a> {
pub request: HttpRequestLine<'a>,
pub headers: Headers<'a>,
pub body: Body<'a>,
}