add new function and fix http1

This commit is contained in:
abbie 2023-07-17 12:41:08 +01:00
parent 12cb863083
commit 03a0cd1919
Signed by: threeoh6000
GPG key ID: 801FE4AD456E922C
3 changed files with 14 additions and 4 deletions

View file

@ -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 <colean@colean.cc>"]
license = "MPL-2.0"

View file

@ -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);
}

View file

@ -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;