feat(request_parser): base code
This commit is contained in:
34
src/http.rs
34
src/http.rs
@@ -1,3 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::io::prelude::*;
|
||||
use std::net::TcpStream;
|
||||
@@ -7,6 +8,19 @@ pub struct ProcessedResponse {
|
||||
status: u8,
|
||||
}
|
||||
|
||||
struct HttpRequestLine {
|
||||
method: String,
|
||||
version: f32,
|
||||
path: String,
|
||||
params: HashMap<String, String>,
|
||||
}
|
||||
|
||||
struct HttpRequest {
|
||||
request: HttpRequestLine,
|
||||
headers: HashMap<String, String>,
|
||||
body: String,
|
||||
}
|
||||
|
||||
pub fn process_petition(stream: &mut TcpStream) -> std::io::Result<ProcessedResponse> {
|
||||
let mut buffer = [0; 1024];
|
||||
|
||||
@@ -36,3 +50,23 @@ pub fn process_petition(stream: &mut TcpStream) -> std::io::Result<ProcessedResp
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
fn parse_request(request_raw: String) -> Result<HttpRequest, i16> {
|
||||
// TODO: study if better to use match
|
||||
if let Some((heading, rest)) = request_raw.split_once("\n") {
|
||||
// Process heading
|
||||
// split heading with split_whitespace
|
||||
// for (i, line) in request_raw.enumerate() {
|
||||
// }
|
||||
if let Some((headers, body)) = rest.split_once("\n\n") {
|
||||
// Process headers and body
|
||||
// split headers over ":"
|
||||
}
|
||||
}
|
||||
|
||||
Err(400)
|
||||
}
|
||||
|
||||
fn parse_request_line(request_line: String) -> HttpRequestLine {
|
||||
if let Some((method, path, version)) = request_line.split_whitespace() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user