add new function and fix http1
This commit is contained in:
parent
12cb863083
commit
03a0cd1919
3 changed files with 14 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "packeteer"
|
name = "packeteer"
|
||||||
description = "An attempt at a Rust library that can be used to assist in programmatically analysing, serving and handling received protocol packets."
|
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"
|
edition = "2021"
|
||||||
authors = ["Celeste <colean@colean.cc>"]
|
authors = ["Celeste <colean@colean.cc>"]
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! The module handling HTTP/1.0 and HTTP/1.1 operations.
|
//! 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 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.
|
//! 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;
|
use std::str::FromStr;
|
||||||
|
|
||||||
/// A structure for HTTP/1.x requests.
|
/// 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.
|
/// 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.
|
/// 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 {
|
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 {
|
for header in request.headers {
|
||||||
unpacked = format!("{}{}: {}\r\n", unpacked, header.key, header.value);
|
unpacked = format!("{}{}: {}\r\n", unpacked, header.key, header.value);
|
||||||
}
|
}
|
||||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -77,6 +77,16 @@ pub fn unwrap_url(input: Url) -> String {
|
||||||
return string.to_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")]
|
#[cfg(feature = "http1")]
|
||||||
pub mod http1;
|
pub mod http1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue