Skip to content

Commit

Permalink
Merge pull request #45 from Basicprogrammer10/dev
Browse files Browse the repository at this point in the history
afire 2.2.0
  • Loading branch information
connorslade authored Jul 2, 2023
2 parents 59bf130 + 1eebb90 commit ceb1c9a
Show file tree
Hide file tree
Showing 34 changed files with 1,633 additions and 992 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*target
/testing
/examples/target
/benches
/examples/target
todo.md
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Connor Slade <[email protected]>"]
edition = "2018"
name = "afire"
version = "2.1.0"
version = "2.2.0"

categories = ["network-programming", "web-programming::http-server"]
description = "🔥 A blazing fast web framework for Rust"
Expand All @@ -27,3 +27,6 @@ tracing = []

[dev-dependencies]
afire = { path = ".", features = ["extensions"] }

[package.metadata.docs.rs]
rustc-args = ["--cfg", "docsrs"]
19 changes: 19 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# 2.2.0

July, 02, 2023

- Use binary search on ServeStatic MMIE types (save those clock cycles)
- Some optimizations throughout afire
- Logger can now make use of the `RealIp` extension and log the real ip of the client
- Logger now holds a persistent file handle instead of opening and closing it every time
- In ServeStatic, when paths have the '..', they will now go up a directory instead of being ignored
Note: The highest you can can go is the data directory that you define, so there is no path traversal vulnerability
- Accept `impl Into<HeaderType>` in `RequestId::new` instead of just `AsRef<str>`.
This allows for using `HeaderType`s as well as strings to set the header.
- Add a `HEAD` middleware that adds support for the HTTP HEAD method.
- Update `ServeStatic` to send a Content-Length header when streaming a file.
- Build extension docs on docs.rs
- Add a `TRACE` middleware that adds support for the HTTP TRACE method.
- Add support for [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) (SSE).
- Progress on Websocket support

# 2.1.0

April 24, 2023
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Just add the following to your `Cargo.toml`:

```toml
[dependencies]
afire = "2.1.0"
afire = "2.2.0"
```

## 📄 Info
Expand Down
1,094 changes: 515 additions & 579 deletions SocialShare.ai

Large diffs are not rendered by default.

Binary file modified SocialShare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion examples/basic/logging.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use afire::{
extension::logger::{Level, Logger},
Content, Method, Middleware, Response, Server,
Content, HeaderType, Method, Middleware, Response, Server,
};

use crate::Example;
Expand Down Expand Up @@ -35,10 +35,14 @@ impl Example for Logging {
// The level of logging this can be Debug or Info
// Debug will give a lot more information about the request
.level(Level::Info)
// This will have Logger make use of the RealIp extention,
// which will allow logging the correct IP when using a reverse proxy.
.real_ip(HeaderType::XForwardedFor)
// The file argument tells the logger if it should save to a file
// Only one file can be defined per logger
// With logging to file it will write to the file on every request... (for now)
.file("example.log")
.unwrap()
// Tells the Logger it should log to the console as well
.console(true)
// This must be put at the end of your Logger Construction
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub trait Example {
}

fn main() {
set_log_level(Level::Debug);
set_log_level(Level::Trace);
let examples: Vec<Box<dyn Example>> = vec![
Box::new(basic::Basic),
Box::new(serve_file::ServeFile),
Expand Down
35 changes: 35 additions & 0 deletions examples/middle_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use afire::{
prelude::*,
trace::{set_log_level, Level},
};

macro_rules! empty_middleware {
($($name:tt,)*) => {
$(
struct $name;
impl Middleware for $name {}
)*
};
}

empty_middleware! {
Middleware1,
Middleware2,
Middleware3,
Middleware4,
Middleware5,
}

fn main() {
set_log_level(Level::Debug);
let mut server = Server::<()>::new([127, 0, 0, 1], 8080);
server.route(Method::ANY, "**", |_req| Response::new());

Middleware1.attach(&mut server);
Middleware2.attach(&mut server);
Middleware3.attach(&mut server);
Middleware4.attach(&mut server);
Middleware5.attach(&mut server);

server.start().unwrap();
}
189 changes: 0 additions & 189 deletions examples/tmp.rs

This file was deleted.

14 changes: 4 additions & 10 deletions lib/extensions/date.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Middleware to add the HTTP Date header (as defined in [RFC 9110, Section 5.6.7](https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.7)).
//! This is technically required for all servers that have a clock, so I may move it to the core library at some point.

use std::time::{SystemTime, UNIX_EPOCH};

use crate::{
internal::common::epoch,
middleware::{MiddleResult, Middleware},
Header, HeaderType, Request, Response,
HeaderType, Request, Response,
};

const DAYS: [&str; 7] = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
Expand All @@ -26,13 +25,8 @@ pub struct Date;

impl Middleware for Date {
fn post(&self, _req: &Request, res: &mut Response) -> MiddleResult {
let epoch = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards. Make sure your date is set correctly.")
.as_secs();

res.headers
.push(Header::new(HeaderType::Date, imp_date(epoch)));
let epoch = epoch().as_secs();
res.headers.add(HeaderType::Date, imp_date(epoch));
MiddleResult::Continue
}
}
Expand Down
Loading

0 comments on commit ceb1c9a

Please sign in to comment.