Skip to content
Snippets Groups Projects
Commit 61af39db authored by codecraft's avatar codecraft :crocodile:
Browse files

Create the FromRequest trait

parent f29d3004
No related branches found
No related tags found
1 merge request!1Initial feature merge
...@@ -10,7 +10,7 @@ use crate::handling::{ ...@@ -10,7 +10,7 @@ use crate::handling::{
}; };
use crate::setup::MountPoint; use crate::setup::MountPoint;
static MAX_HTTPMESSAGE_SIZE: u16 = 4196; static MAX_HTTP_MESSAGE_SIZE: u16 = 4196;
pub async fn handle_connection(mut stream: TcpStream, mountpoints: Vec<MountPoint<'_>>) { pub async fn handle_connection(mut stream: TcpStream, mountpoints: Vec<MountPoint<'_>>) {
let mut buf_reader = BufReader::new(&mut stream); let mut buf_reader = BufReader::new(&mut stream);
...@@ -88,7 +88,7 @@ pub async fn handle_connection(mut stream: TcpStream, mountpoints: Vec<MountPoin ...@@ -88,7 +88,7 @@ pub async fn handle_connection(mut stream: TcpStream, mountpoints: Vec<MountPoin
0 0
}; };
if length != 0 { if length != 0 {
let mut buffer = vec![0u8; MAX_HTTPMESSAGE_SIZE.into()]; let mut buffer = vec![0u8; MAX_HTTP_MESSAGE_SIZE.into()];
let read = buf_reader.read(&mut buffer).await.unwrap(); let read = buf_reader.read(&mut buffer).await.unwrap();
if read != length { if read != length {
len_not_defined(stream, Status::LengthRequired).await; len_not_defined(stream, Status::LengthRequired).await;
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
use std::{collections::HashMap, error::Error, fmt::Display}; use std::{collections::HashMap, error::Error, fmt::Display};
use tokio::io::BufReader;
use crate::utils::mime::mime_enum::Mime; use crate::utils::mime::mime_enum::Mime;
static TWO_NEWLINES: u8 = 3; static TWO_NEWLINES: u8 = 3;
...@@ -13,7 +11,27 @@ use super::{ ...@@ -13,7 +11,27 @@ use super::{
routes::{Data, Uri}, routes::{Data, Uri},
}; };
pub trait FromRequest: Send {
fn get_data(&self) -> &Self;
fn set_data(&mut self, data: &Self);
fn append(&mut self, data: &Self);
}
impl FromRequest for Vec<u8> {
fn get_data(&self) -> &Self {
&self
}
fn set_data(&mut self, data: &Self) {
*self = data.to_vec();
}
fn append(&mut self, data: &Self) {
self.extend_from_slice(data);
}
}
type HeaderMap = Vec<String>; type HeaderMap = Vec<String>;
#[derive(Clone)] #[derive(Clone)]
pub struct Request<'a> { pub struct Request<'a> {
pub uri: Uri<'a>, pub uri: Uri<'a>,
...@@ -203,7 +221,7 @@ impl Request<'_> { ...@@ -203,7 +221,7 @@ impl Request<'_> {
let end_boundary = format!("{temp_bound}--\r").as_bytes().to_owned(); let end_boundary = format!("{temp_bound}--\r").as_bytes().to_owned();
temp_bound.push('\r'); temp_bound.push('\r');
let boundary = temp_bound.as_bytes(); let boundary = temp_bound.as_bytes();
Request::get_multipart(data, boundary, &end_boundary, &mut keymap); Request::get_multipart_data(data, boundary, &end_boundary, &mut keymap);
} }
_ => { _ => {
return Err(ParseFormError { return Err(ParseFormError {
...@@ -213,15 +231,6 @@ impl Request<'_> { ...@@ -213,15 +231,6 @@ impl Request<'_> {
}; };
Ok(keymap) Ok(keymap)
} }
fn decode_multipart<'a>(
data: &Data,
keys: &[&'a str],
) -> HashMap<String, Result<Vec<u8>, ParseFormError>> {
let mut data = data.buffer.as_ref();
let mut buf_reader = BufReader::new(&mut data);
let mut http_request: Vec<String> = Vec::with_capacity(2);
todo!()
}
fn get_multipart_data( fn get_multipart_data(
data: &[u8], data: &[u8],
boundary: &[u8], boundary: &[u8],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment