From 03a0cd1919e123ad3a458be4ca12183b3bdc934b Mon Sep 17 00:00:00 2001 From: threeoh6000 Date: Mon, 17 Jul 2023 12:41:08 +0100 Subject: [PATCH] add new function and fix http1 --- Cargo.toml | 2 +- src/http1.rs | 4 ++-- src/lib.rs | 12 +++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index db2fb25..4b2998c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "packeteer" description = "An attempt at a Rust library that can be used to assist in programmatically analysing, serving and handling received protocol packets." -version = "0.5.0" +version = "0.5.1" edition = "2021" authors = ["Celeste "] license = "MPL-2.0" diff --git a/src/http1.rs b/src/http1.rs index 7adf597..2bfd491 100644 --- a/src/http1.rs +++ b/src/http1.rs @@ -1,7 +1,7 @@ //! The module handling HTTP/1.0 and HTTP/1.1 operations. //! It contains structures for HTTP/1.x requests and responses as well as functions for generating, unpacking and constructing them. //! It can also upgrade and downgrade HTTP/1.x requests. -use super::{KVHeader, generate_kvheader, Url, wrap_url, unwrap_url}; +use super::{KVHeader, generate_kvheader, Url, wrap_url, unwrap_url_into_segments}; use std::str::FromStr; /// A structure for HTTP/1.x requests. @@ -113,7 +113,7 @@ pub fn construct_response(response: &str) -> Http1Response { /// A function for converting Http1Request structures into HTTP/1.x request strings. /// Unpacking functions are simply taking the data stored in the structure and concatenating it into a string so nothing changes apart from the conversion. pub fn unpack_request(request: Http1Request) -> String { - let mut unpacked = format!("{} {} HTTP/{}\r\n", request.method, unwrap_url(request.location).replace("https://root/","/"), request.version); + let mut unpacked = format!("{} {} HTTP/{}\r\n", request.method, unwrap_url_into_segments(request.location), request.version); for header in request.headers { unpacked = format!("{}{}: {}\r\n", unpacked, header.key, header.value); } diff --git a/src/lib.rs b/src/lib.rs index 3e79593..07ef2b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ //! packeteer = { version = "0.4", features = ["http1"] } //! ``` //! -//! It's safe to use ambigious version numbers that exclude the bugfix number as breaking changes or new features will result in an increment of the minor version number, or possibly major version number in the future. +//! It's safe to use ambigious version numbers that exclude the bugfix number as breaking changes or new features will result in an increment of the minor version number, or possibly major version number in the future. //! //! Packeteer aims to use as little dependencies as possible. The less dependenices that packeteer uses, the less storage your project uses. Being conservative with dependencies also makes compilation infinitely faster. //! @@ -77,6 +77,16 @@ pub fn unwrap_url(input: Url) -> String { return string.to_string(); } +/// A public function that returns just a Url's segments as one string. +pub fn unwrap_url_into_segments(input: Url) -> String { + let mut string = format!(""); + for v in input.segments { + string = format!("{}/{}", string, v); + } + if string.to_string() == "".to_string() { return "/".to_string(); } + return string.to_string(); +} + #[cfg(feature = "http1")] pub mod http1;