Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into beanow/patch-httpz
Browse files Browse the repository at this point in the history
Signed-off-by: Oscar Beaumont <[email protected]>
  • Loading branch information
oscartbeaumont authored Oct 13, 2023
2 parents 569cc77 + f3050d0 commit 758e61d
Show file tree
Hide file tree
Showing 24 changed files with 240 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
42 changes: 30 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
---
name: CI

on:
workflow_dispatch:
workflow_dispatch: null
push:
branches:
- main
pull_request:

pull_request: null
env:
CARGO_TERM_COLOR: always

jobs:
build:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v4
- name: "[Linux] System dependencies"
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev
- name: Run tests
run: cargo test --all-features --verbose

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: System dependencies
run: sudo apt-get update && sudo apt-get install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
23 changes: 0 additions & 23 deletions .github/workflows/clippy.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/upgrade-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
env:
BRANCH_NAME: auto-dependency-upgrades
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# This is required to run CI workflow on PR created by this workflow
# https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#push-using-ssh-deploy-keys
Expand Down
47 changes: 25 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,42 +42,45 @@ warp = ["dep:warp"]
lambda = ["dep:lambda_http", "dep:tower"]
workers = ["dep:worker"]
tauri = ["dep:tauri", "dep:percent-encoding", "dep:tokio"] # TODO: Remove tokio dep once my wry & Tauri PR's are merged
vercel = ["dep:vercel_runtime"]

[dependencies]
# Webservers
actix-web = { version = "4.2.1", optional = true, features = [] }
axum = { version = "0.6.1", optional = true, features = [] }
poem = { version = "1.3.45", optional = true, features = [] }
rocket = { version = "0.5.0-rc.2", optional = true, features = [] }
warp = { version = "0.3.3", optional = true, features = [] }
lambda_http = { version = "0.7.2", optional = true, features = [] }
actix-web = { version = "4.3.1", optional = true, features = [] }
axum = { version = "0.6.19", optional = true, features = [] }
poem = { version = "1.3.56", optional = true, features = [] }
rocket = { version = "0.5.0-rc.3", optional = true, features = [] }
warp = { version = "0.3.5", optional = true, features = [] }
lambda_http = { version = "0.8.1", optional = true, features = [] }
tower = { version = "0.4.13", optional = true, features = [] }
worker = { version = "0.0.12", optional = true, features = [] }
tauri = { version = "1.2.4", optional = true, features = ["linux-protocol-headers"] }
worker = { version = "0.0.17", optional = true, features = [] }
tauri = { version = "1.4.1", optional = true, features = ["linux-protocol-headers"] }
vercel_runtime = { version = "1.0.2", optional = true }

# Core
cookie = { version = "0.16.1", optional = true, features = ["percent-encode"] }
http = { version = "0.2.8", features = [] }
form_urlencoded = "1.1.0"
cookie = { version = "0.17.0", optional = true, features = ["percent-encode"] }
http = { version = "0.2.9", features = [] }
form_urlencoded = "1.2.0"
async-tungstenite = { version = "0.23.0", optional = true }
sha1 = { version = "0.10.5", optional = true }
base64 = { version = "0.20.0", optional = true }
tokio = { version = "1.21.2", features = [], default-features = false, optional = true }
hyper = "0.14.20" # TODO: Remove this if possible or feature gate it. I think Axum needs it.
futures = "0.3.24"
thiserror = "1.0.37"
percent-encoding = { version = "2.2.0", optional = true, features = [] }
base64 = { version = "0.21.2", optional = true }
tokio = { version = "1.29.1", features = [], default-features = false, optional = true }
hyper = "0.14.27" # TODO: Remove this if possible or feature gate it. I think Axum needs it.
futures = "0.3.28"
thiserror = "1.0.43"
percent-encoding = { version = "2.3.0", optional = true, features = [] }

[dev-dependencies]
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread", "fs"] }
axum = { version = "0.6.1", features = [] }
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread", "fs"] }
axum = { version = "0.6.19", features = [] }
tower = { version = "0.4.13", features = [] }
hyper = { version = "0.14.20", features = [] }
actix-web = "4.2.1"
hyper = { version = "0.14.27", features = [] }
actix-web = "4.3.1"

[workspace]
members = [
"./examples/cf-workers",
"./examples/netlify/netlify/functions/demo",
"./examples/tauri"
"./examples/tauri",
"./examples/vercel"
]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<h1>httpz</h1>
<p><b>Code once, support every Rust webserver!</b></p>
<a href="https://discord.gg/4V9M5sksw8"><img src="https://img.shields.io/discord/1011665225809924136?style=flat-square" alt="Discord"></a>
<a href="https://discord.gg/JgqH8b4ycw"><img src="https://img.shields.io/discord/1011665225809924136?style=flat-square" alt="Discord"></a>
<a href="https://crates.io/crates/httpz"><img src="https://img.shields.io/crates/d/httpz?style=flat-square" alt="Crates.io"></a>
<a href="/LICENSE"><img src="https://img.shields.io/crates/l/httpz?style=flat-square" alt="License"></a>
</div>
Expand Down
14 changes: 6 additions & 8 deletions examples/axum_with_state.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
use axum::{extract::State, response::IntoResponse, Extension, RequestPartsExt};
use httpz::{
http::{Method, Response, StatusCode},
GenericEndpoint, Request,
};

#[derive(Debug, Clone)]
pub struct MyCtx;

#[cfg(feature = "axum")]
#[tokio::main]
async fn main() {
use httpz::{
http::{Method, Response, StatusCode},
GenericEndpoint, Request,
};

let endpoint = GenericEndpoint::new(
"/*any",
[Method::GET, Method::POST],
|req: Request| async move {
// If the generic here doesn't match your Axum router it will return `None`. This isn't super typesafe but it's what you get for having to support 10 different web frameworks.
let axum_state = req.get_axum_state::<MyCtx>().unwrap();
let (mut parts, body) = req.into_parts();
let _axum_state = req.get_axum_state::<MyCtx>().unwrap();

Ok(Response::builder()
.status(StatusCode::OK)
Expand Down
4 changes: 2 additions & 2 deletions examples/cf-workers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ default = ["console_error_panic_hook"]
[dependencies]
httpz = { path = "../../", features = ["workers"] }
cfg-if = "1.0.0"
worker = "0.0.12"
serde_json = "1.0.85"
worker = "0.0.17"
serde_json = "1.0.103"

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
Expand Down
8 changes: 4 additions & 4 deletions examples/netlify/netlify/functions/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish = false

[dependencies]
httpz = { path = "../../../../../", features = ["lambda"] }
tokio = "1.21.2"
lambda_http = "0.7.2"
tracing-subscriber = "0.3.15"
tracing = "0.1.36"
tokio = "1.29.1"
lambda_http = "0.8.1"
tracing-subscriber = "0.3.17"
tracing = "0.1.37"
4 changes: 2 additions & 2 deletions examples/netlify/netlify/functions/demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use httpz::{
http::{Method, StatusCode},
GenericEndpoint, Request,
};
use lambda_http::{run, Error, Response};
use lambda_http::{Error, Response};

#[tokio::main]
async fn main() -> Result<(), Error> {
Expand All @@ -23,5 +23,5 @@ async fn main() -> Result<(), Error> {
);

// TODO: URL Prefix
run(endpoint.lambda()).await
endpoint.lambda().await
}
4 changes: 2 additions & 2 deletions examples/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ rust-version = "1.57"
publish = false

[build-dependencies]
tauri-build = { version = "1.2", features = [] }
tauri-build = { version = "1.4", features = [] }

[dependencies]
httpz = { path = "../../", features = ["tauri"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2", features = ["linux-protocol-headers", "shell-open"] } # "linux-protocol-headers" is highly reccomended for usage with httpz
tauri = { version = "1.4", features = ["linux-protocol-headers", "shell-open"] } # "linux-protocol-headers" is highly reccomended for usage with httpz

[features]
# by default Tauri runs in production mode
Expand Down
1 change: 1 addition & 0 deletions examples/vercel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
14 changes: 14 additions & 0 deletions examples/vercel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "httpz-vercel-demo"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1", features = ["macros"] }
serde_json = { version = "1.0.103", features = ["raw_value"] }
httpz = { path = "../..", features = ["vercel"] }
vercel_runtime = { version = "1.0.2" }

[[bin]]
name = "simple"
path = "api/simple.rs"
20 changes: 20 additions & 0 deletions examples/vercel/api/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use httpz::{
http::{Method, Response, StatusCode},
GenericEndpoint, Request,
};

#[tokio::main]
async fn main() {
let endpoint = GenericEndpoint::new(
"/*any", // TODO: Make this wildcard work
[Method::GET, Method::POST],
|_req: Request| async move {
Ok(Response::builder()
.status(StatusCode::OK)
.header("Content-Type", "text/html")
.body(b"httpz running on Vercel!".to_vec())?)
},
);

endpoint.vercel().await.unwrap()
}
8 changes: 8 additions & 0 deletions examples/vercel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "httpz-vercel-demo",
"version": "1.0.0",
"description": "",
"keywords": [],
"license": "ISC",
"author": ""
}
7 changes: 7 additions & 0 deletions examples/vercel/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"functions": {
"api/**/*.rs": {
"runtime": "[email protected]"
}
}
}
2 changes: 1 addition & 1 deletion examples/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn main() {
// Attach your endpoint to a HTTP server. This example uses Axum but it could be any other one.
let app = axum::Router::new().nest("/", endpoint.axum());
#[cfg(feature = "cookies")]
let app = app.route("/cookiesws", endpoint2.axum());
let app = app.nest("/cookiesws", endpoint2.axum());

let addr = "[::]:9000".parse::<std::net::SocketAddr>().unwrap(); // This listens on IPv6 and IPv4
println!("Axum listening on http://{}", addr);
Expand Down
7 changes: 7 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub enum Server {
/// support for [Hyper](https://github.com/hyperium/hyper)
#[cfg(feature = "hyper")]
Hyper,
/// support for [Vercel](https://github.com/vercel-community/rust)
#[cfg(feature = "vercel")]
Vercel,
}

impl Server {
Expand All @@ -53,6 +56,8 @@ impl Server {
Self::Tauri => "tauri",
#[cfg(feature = "hyper")]
Self::Hyper => "hyper",
#[cfg(feature = "vercel")]
Self::Vercel => "vercel",
_ => unreachable!(),
}
}
Expand All @@ -79,6 +84,8 @@ impl Server {
Self::Tauri => false,
#[cfg(feature = "hyper")]
Self::Hyper => false,
#[cfg(feature = "vercel")]
Self::Vercel => false,
_ => unreachable!(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/servers/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where

let mut method_filter = MethodFilter::empty();
for method in methods.as_ref().iter() {
// TODO: Error handling
#[allow(clippy::unwrap_used)] // TODO: Error handling
method_filter.insert(MethodFilter::try_from(method.clone()).unwrap());
}

Expand Down
Loading

0 comments on commit 758e61d

Please sign in to comment.