clean up repo a bit and fix #1

This commit is contained in:
abbie 2024-01-15 15:11:12 +00:00
parent 03a0cd1919
commit fcbb47cfe5
Signed by: threeoh6000
GPG key ID: 801FE4AD456E922C
4 changed files with 7 additions and 54 deletions

View file

@ -1,9 +1,9 @@
[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.1" version = "0.5.2"
edition = "2021" edition = "2021"
authors = ["Celeste <colean@colean.cc>"] authors = ["abbieoverflight <abbieoverflight@colean.cc>"]
license = "MPL-2.0" license = "MPL-2.0"
homepage = "https://git.colean.cc/threeoh6000/packeteer/" homepage = "https://git.colean.cc/threeoh6000/packeteer/"
repository = "https://git.colean.cc/threeoh6000/packeteer/" repository = "https://git.colean.cc/threeoh6000/packeteer/"

25
README
View file

@ -1,25 +0,0 @@
Packeteer
-------------
Packeteer is a library that can handle structurally organising protocol packets like HTTP 1.x requests and responses as well as generating, structuring, unpacking and potentially more features depending on the protocol.
Supported protocols
-----------------------
* HTTP/1.x
* Gemini
* FTP
* DNS
What Packeteer is not
-------------------------
* a TCP/UDP stream handling library
* a server
* a protocol client
* the only way to do this, probably
A note on licensing
-----------------------
This library changed from the LGPLv3 to MPLv2 as a result of LGPL's requirements for freedom of source on static linking which rustc does.
I've chosen to use the MPL as it is a weaker but still copyleft license that allows you to statically link.
The MPL applies retroactively to all previous versions of this library and will be used for all future versions.

View file

@ -1,25 +0,0 @@
<h1>Packeteer</h1>
<p>Packeteer is a library that can handle structurally organising protocol packets like HTTP 1.x requests and responses as well as generating, structuring, unpacking and potentially more features depending on the protocol.</p>
<h2>Supported protocols</h2>
<ul>
<li>HTTP/1.x</li>
<li>Gemini</li>
<li>FTP</li>
<li>DNS</li>
</ul>
<h2>What Packeteer is not</h2>
<ul>
<li>a TCP/UDP stream handling library</li>
<li>a server</li>
<li>a protocol client</li>
<li>the only way to do this, probably</li>
</ul>
<h2>A note on licensing</h2>
<p>This library changed from the LGPLv3 to MPLv2 as a result of LGPL's requirements for freedom of source on static linking which rustc does.</p>
<p>I've chosen to use the MPL as it is a weaker but still copyleft license that allows you to statically link.</p>
<p>The MPL applies retroactively to all previous versions of this library and will be used for all future versions.</p>

View file

@ -45,7 +45,7 @@ pub fn generate_response(code: i32, body: &str) -> Http1Response {
} }
/// A function for converting HTTP/1.x request strings into Http1Request. /// A function for converting HTTP/1.x request strings into Http1Request.
/// Construction functions aim to be as transparent as possible so apart from turning it into a structure, the request stays relatively unchanged. /// Construction functions aim to be as transparent as possible so apart from turning it into a structure, the request stays relatively unchanged.
pub fn construct_request(request: &str) -> Http1Request { pub fn construct_request(request: &str) -> Option<Http1Request> {
let split = request.split("\r\n"); let split = request.split("\r\n");
let mut request = Http1Request { method: "".to_string(), location: wrap_url("https://example.com"), version: "".to_string(), headers: vec![], body: "".to_string() }; let mut request = Http1Request { method: "".to_string(), location: wrap_url("https://example.com"), version: "".to_string(), headers: vec![], body: "".to_string() };
let mut reachedbody = false; let mut reachedbody = false;
@ -64,6 +64,9 @@ pub fn construct_request(request: &str) -> Http1Request {
} else if v == "" { } else if v == "" {
reachedbody = true; reachedbody = true;
} else { } else {
if request.version == "".to_string() {
return None;
}
let split1: Vec<&str> = v.split(": ").collect(); let split1: Vec<&str> = v.split(": ").collect();
let header = generate_kvheader(split1[0], split1[1]); let header = generate_kvheader(split1[0], split1[1]);
request.headers.push(header) request.headers.push(header)
@ -72,7 +75,7 @@ pub fn construct_request(request: &str) -> Http1Request {
request.body = v.to_string(); request.body = v.to_string();
} }
} }
return request return Some(request)
} }
/// A function for converting HTTP/1.x response strings into Http1Response. /// A function for converting HTTP/1.x response strings into Http1Response.
/// Construction functions aim to be as transparent as possible so apart from turning it into a structure, the response stays relatively unchanged. /// Construction functions aim to be as transparent as possible so apart from turning it into a structure, the response stays relatively unchanged.