Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fork changes #15

Closed
wants to merge 88 commits into from
Closed

Fork changes #15

wants to merge 88 commits into from

Conversation

sigaloid
Copy link
Contributor

@sigaloid sigaloid commented Jan 8, 2022

Compression is borked so I've removed the feature from Cargo.toml but the code is there (dormant).

@sigaloid sigaloid mentioned this pull request Jan 8, 2022
Comment on lines +13 to +14
# Why not PR?
* Author has been inactive since Dec 2020, and I really like this framework and want to see it improved. :)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this as you see fit or let me know to remove it

@@ -0,0 +1,98 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file benchmarks the parsing of HTTP requests with this library

@@ -0,0 +1,31 @@
[package]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for fuzzing of the requests, meaning we can check invalid requests to see if they cause panics

Comment on lines -157 to +163
let cookie = Cookie::parse(cookie).map_err(|e| Error::Other(e.to_string()))?;
let name = cookie.name().to_owned();
let val = util::percent_decode(cookie.value()).unwrap();
req.cookies.push((name, val));
if let Ok(cookies) = Cookie::parse(&cookie.into_owned()) {
for cookie in cookies {
req.cookies.push((
cookie.get_name().to_string(),
cookie.get_value().to_string(),
));
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old cookie crate was for parsing singular cookies, not the entire header at once

Comment on lines +400 to +419
pub fn user_agent(&self) -> Option<String> {
self.header("User-Agent").map(|ua| ua.to_string())
}
/// Return the Do Not Track header
#[must_use]
pub fn do_not_track(&self) -> bool {
match self.header("DNT") {
Some(dnt) => dnt == "1",
None => false,
}
}
/// Return the Accept-Language, if exists
#[must_use]
pub fn accept_language(&self) -> Option<String> {
self.header("Accept-Language").map(|al| al.to_string())
}
/// Return the content-type, if exists
#[must_use]
pub fn content_type(&self) -> Option<String> {
self.header("Content-Type").map(|ct| ct.to_string())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are a bit opinionated imo but I found them helpful. Feel free to remove

/// Starts a new Vial server. Should always be invoked via the
/// [`vial::run!()`](macro.run.html) macro, since there is some setup
/// that needs to happen.
#[doc(hidden)]
pub fn run<T: ToSocketAddrs>(addr: T, router: Router, banner: Option<&str>) -> Result<()> {
let pool = ThreadPool::new(MAX_CONNECTIONS);
// If a range is supplied, the lower bound will be the core pool size while the upper bound will be a maximum pool size the pool is allowed to burst up to when the core threads are busy.
let pool = threadfin::builder().size(1..=128).build();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Threadfin (https://lib.rs/threadfin) allows for far easier thread management!

let stream = stream.try_clone()?;
// discard because: https://doc.rust-lang.org/std/net/struct.TcpStream.html#method.set_read_timeout
// "An Err is returned if the zero Duration is passed to this method." thus no need to check result
drop(stream.set_read_timeout(Some(Duration::from_millis(1000))));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slow loris attack 😞

let next_pct = match inp.find('%') {
Some(l) if l < inp.len() - 2 => l,
Some(l) if l < if inp.len() > 1 { inp.len() - 2 } else { 0 } => l,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit of a botchy fix for the header issue but it caused thread panics so I quickly fixed it

@@ -0,0 +1,93 @@
#![allow(non_snake_case)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement some tests for cookies

assert_eq!(200, res.code());
assert_eq!(771638, res.len());
}
// Somehow disabling this godforsaken test resolves the sporadic test failure.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the library-wide unsafes! Tests are multithreaded... Start one test that spawns the rest sequentially

@xvxx
Copy link
Owner

xvxx commented Jan 8, 2022

I'd be open to looking at these as individual PRs but I'm not going to review a mega-PR, sorry!

@xvxx xvxx closed this Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants