From 73bbd639c25ae5f20688da1473f1a42d5664afec Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Fri, 17 Mar 2023 11:32:16 +0800 Subject: [PATCH 1/8] vercel endpoint (#30) * vercel endpoint * vercel server enum variant * vercel example * praise lord clippy * ci moment * CI fixes * add more deps * plz be the last one * more more more more more more deps * remove main requirement from CI workflow * GH Actions is on crack * fix it * Yaml is cringae * Yaml hurts me * CI all features * a few fixes --------- Co-authored-by: Oscar Beaumont --- .github/workflows/ci.yml | 41 ++++++++++++++++++-------- .github/workflows/clippy.yml | 23 --------------- Cargo.toml | 5 +++- examples/axum_with_state.rs | 14 ++++----- examples/vercel/.gitignore | 1 + examples/vercel/Cargo.toml | 14 +++++++++ examples/vercel/api/simple.rs | 20 +++++++++++++ examples/vercel/package.json | 8 +++++ examples/vercel/vercel.json | 7 +++++ examples/websocket.rs | 2 +- src/server.rs | 7 +++++ src/servers/axum.rs | 2 +- src/servers/mod.rs | 4 +++ src/servers/tauri.rs | 3 ++ src/servers/vercel.rs | 55 +++++++++++++++++++++++++++++++++++ src/ws/tokio_ws.rs | 10 +++---- 16 files changed, 164 insertions(+), 52 deletions(-) delete mode 100644 .github/workflows/clippy.yml create mode 100644 examples/vercel/.gitignore create mode 100644 examples/vercel/Cargo.toml create mode 100644 examples/vercel/api/simple.rs create mode 100644 examples/vercel/package.json create mode 100644 examples/vercel/vercel.json create mode 100644 src/servers/vercel.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f9ca0b..1347cea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,24 +1,41 @@ +--- 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@v3 + - name: "[Linux] System dependencies" + if: matrix.os == 'ubuntu-latest' + run: 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@v3 + - name: System dependencies + run: 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 diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml deleted file mode 100644 index 316b191..0000000 --- a/.github/workflows/clippy.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Clippy - -on: - workflow_dispatch: - push: - branches: - - main - pull_request: - -jobs: - clippy_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - 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 \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 14d67fa..afc7b12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,7 @@ 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 @@ -54,6 +55,7 @@ lambda_http = { version = "0.7.2", 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"] } +vercel_runtime = { version = "0.2.1", optional = true } # Core cookie = { version = "0.16.1", optional = true, features = ["percent-encode"] } @@ -79,5 +81,6 @@ actix-web = "4.2.1" members = [ "./examples/cf-workers", "./examples/netlify/netlify/functions/demo", - "./examples/tauri" + "./examples/tauri", + "./examples/vercel" ] diff --git a/examples/axum_with_state.rs b/examples/axum_with_state.rs index 1ad9f81..0a15831 100644 --- a/examples/axum_with_state.rs +++ b/examples/axum_with_state.rs @@ -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::().unwrap(); - let (mut parts, body) = req.into_parts(); + let _axum_state = req.get_axum_state::().unwrap(); Ok(Response::builder() .status(StatusCode::OK) diff --git a/examples/vercel/.gitignore b/examples/vercel/.gitignore new file mode 100644 index 0000000..e985853 --- /dev/null +++ b/examples/vercel/.gitignore @@ -0,0 +1 @@ +.vercel diff --git a/examples/vercel/Cargo.toml b/examples/vercel/Cargo.toml new file mode 100644 index 0000000..ceeee56 --- /dev/null +++ b/examples/vercel/Cargo.toml @@ -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.86", features = ["raw_value"] } +httpz = { path = "../..", features = ["vercel"] } +vercel_runtime = { version = "0.2.1" } + +[[bin]] +name = "simple" +path = "api/simple.rs" diff --git a/examples/vercel/api/simple.rs b/examples/vercel/api/simple.rs new file mode 100644 index 0000000..453e8e1 --- /dev/null +++ b/examples/vercel/api/simple.rs @@ -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() +} diff --git a/examples/vercel/package.json b/examples/vercel/package.json new file mode 100644 index 0000000..b6f90fc --- /dev/null +++ b/examples/vercel/package.json @@ -0,0 +1,8 @@ +{ + "name": "httpz-vercel-demo", + "version": "1.0.0", + "description": "", + "keywords": [], + "license": "ISC", + "author": "" +} diff --git a/examples/vercel/vercel.json b/examples/vercel/vercel.json new file mode 100644 index 0000000..88678ee --- /dev/null +++ b/examples/vercel/vercel.json @@ -0,0 +1,7 @@ +{ + "functions": { + "api/**/*.rs": { + "runtime": "vercel-rust@4.0.0-beta.1" + } + } +} diff --git a/examples/websocket.rs b/examples/websocket.rs index faf98ae..a5d690a 100644 --- a/examples/websocket.rs +++ b/examples/websocket.rs @@ -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::().unwrap(); // This listens on IPv6 and IPv4 println!("Axum listening on http://{}", addr); diff --git a/src/server.rs b/src/server.rs index c97b5d3..421c3f1 100644 --- a/src/server.rs +++ b/src/server.rs @@ -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 { @@ -53,6 +56,8 @@ impl Server { Self::Tauri => "tauri", #[cfg(feature = "hyper")] Self::Hyper => "hyper", + #[cfg(feature = "vercel")] + Self::Vercel => "vercel", _ => unreachable!(), } } @@ -79,6 +84,8 @@ impl Server { Self::Tauri => false, #[cfg(feature = "hyper")] Self::Hyper => false, + #[cfg(feature = "vercel")] + Self::Vercel => false, _ => unreachable!(), } } diff --git a/src/servers/axum.rs b/src/servers/axum.rs index 25da68b..462b5a3 100644 --- a/src/servers/axum.rs +++ b/src/servers/axum.rs @@ -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()); } diff --git a/src/servers/mod.rs b/src/servers/mod.rs index d5333fe..5a8e856 100644 --- a/src/servers/mod.rs +++ b/src/servers/mod.rs @@ -33,3 +33,7 @@ pub mod tauri; /// support for [Hyper](https://github.com/hyperium/hyper) #[cfg(feature = "hyper")] pub mod hyper; + +/// support for [Vercel](https://github.com/vercel-community/rust) +#[cfg(feature = "vercel")] +pub mod vercel; diff --git a/src/servers/tauri.rs b/src/servers/tauri.rs index ebad763..b8cde21 100644 --- a/src/servers/tauri.rs +++ b/src/servers/tauri.rs @@ -31,6 +31,7 @@ where move |handle, req| { let resp = if !methods.contains(req.method()) { + #[allow(clippy::unwrap_used)] // TODO: Error handling http::Response::builder().status(405).body(vec![]).unwrap() } else { let uri = req.uri(); @@ -49,6 +50,7 @@ where for (key, value) in req.headers() { r = r.header(key, value); } + #[allow(clippy::unwrap_used)] // TODO: Error handling let req = r.body(req.body().clone()).unwrap(); // TODO: Avoid clone once my upstream PR merges + error handling // TODO: This blocking sucks but is required for now. https://github.com/tauri-apps/wry/pull/872 @@ -60,6 +62,7 @@ where Ok(resp) => resp, Err(_err) => { // TODO: Do something with `_err` + #[allow(clippy::unwrap_used)] // TODO: Error handling http::Response::builder().status(500).body(vec![]).unwrap() } } diff --git a/src/servers/vercel.rs b/src/servers/vercel.rs new file mode 100644 index 0000000..59c3973 --- /dev/null +++ b/src/servers/vercel.rs @@ -0,0 +1,55 @@ +use http::{Response, StatusCode}; +use std::sync::Arc; +use vercel_runtime::{Body, Error}; + +use crate::{Endpoint, HttpEndpoint, HttpResponse, Server}; + +impl Endpoint +where + TEndpoint: HttpEndpoint, +{ + /// is called to mount the endpoint onto the Vercel runtime. + pub async fn vercel(mut self) -> Result<(), Error> { + let (_url, methods) = self.endpoint.register(); + // TODO: Handle `_url`?? + + let endpoint = Arc::new(self.endpoint); + + vercel_runtime::run(|request| { + let endpoint = endpoint.clone(); + let methods = &methods; + async move { + let is_correct_method = methods.as_ref().contains(request.method()); + + if !is_correct_method { + return Ok(Response::builder() + .status(StatusCode::METHOD_NOT_ALLOWED) + .body("Method Not Allowed".to_string().into())?); + } + + let (parts, body) = request.into_parts(); + let fut = endpoint.handler(crate::Request( + parts, + match body { + Body::Empty => vec![], + Body::Text(text) => text.into_bytes(), + Body::Binary(binary) => binary, + }, + Server::Vercel, + )); + + match fut.await.into_response() { + Ok(resp) => { + let (parts, body) = resp.into_parts(); + Ok(Response::from_parts(parts, body.into())) + } + Err(err) => Ok(Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .header("content-type", "text/html") + .body(err.to_string().into())?), + } + } + }) + .await + } +} diff --git a/src/ws/tokio_ws.rs b/src/ws/tokio_ws.rs index 270dc18..10cca8a 100644 --- a/src/ws/tokio_ws.rs +++ b/src/ws/tokio_ws.rs @@ -31,8 +31,7 @@ impl WebsocketUpgrade { handler: THandler, ) -> WebSocketUpgradeResponse where - THandler: - for<'a> FnOnce(Request, Box) -> TFut + Send + Sync + 'static, + THandler: FnOnce(Request, Box) -> TFut + Send + Sync + 'static, TFut: Future + Send + 'static, { WebSocketUpgradeResponse { @@ -51,8 +50,7 @@ impl WebsocketUpgrade { handler: THandler, ) -> WebSocketUpgradeResponse where - THandler: - for<'a> FnOnce(Request, Box) -> TFut + Send + Sync + 'static, + THandler: FnOnce(Request, Box) -> TFut + Send + Sync + 'static, TFut: Future + Send + 'static, { WebSocketUpgradeResponse { @@ -66,7 +64,7 @@ impl WebsocketUpgrade { /// TODO pub struct WebSocketUpgradeResponse where - THandler: for<'a> FnOnce(Request, Box) -> TFut + Send + Sync + 'static, + THandler: FnOnce(Request, Box) -> TFut + Send + Sync + 'static, TFut: Future + Send + 'static, { req: Request, @@ -78,7 +76,7 @@ where // By only spawning the tokio task here, we ensure we aren't spawning tasks if the user forgets to return the websocket upgrade response from the handler. impl HttpResponse for WebSocketUpgradeResponse where - THandler: for<'a> FnOnce(Request, Box) -> TFut + Send + Sync + 'static, + THandler: FnOnce(Request, Box) -> TFut + Send + Sync + 'static, TFut: Future + Send + 'static, { fn into_response(mut self) -> Result>, Error> { From be67ead9320095bdecf90cae75fded2411509b0f Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Fri, 17 Mar 2023 12:00:00 +0800 Subject: [PATCH 2/8] call serverless runners internally (#29) --- .../netlify/functions/demo/src/main.rs | 4 +- src/servers/lambda.rs | 130 ++++++------------ 2 files changed, 41 insertions(+), 93 deletions(-) diff --git a/examples/netlify/netlify/functions/demo/src/main.rs b/examples/netlify/netlify/functions/demo/src/main.rs index 4cc8ee3..1fe4e05 100644 --- a/examples/netlify/netlify/functions/demo/src/main.rs +++ b/examples/netlify/netlify/functions/demo/src/main.rs @@ -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> { @@ -23,5 +23,5 @@ async fn main() -> Result<(), Error> { ); // TODO: URL Prefix - run(endpoint.lambda()).await + endpoint.lambda().await } diff --git a/src/servers/lambda.rs b/src/servers/lambda.rs index ec5b4c0..f66f145 100644 --- a/src/servers/lambda.rs +++ b/src/servers/lambda.rs @@ -1,106 +1,54 @@ use http::StatusCode; -use lambda_http::{Body, Request, Response, Service}; -use std::{ - future::Future, - sync::Arc, - task::{Context, Poll}, -}; +use lambda_http::{service_fn, Body, Error, Request, Response}; +use std::sync::Arc; use crate::{Endpoint, HttpEndpoint, HttpResponse, Server}; -/// TODO -pub trait InternalTowerHandlerFunc: Fn(Arc, Request) -> Self::Fut -where - TEndpoint: HttpEndpoint, -{ - /// TODO - type Fut: Future, http::Error>> + Send + 'static; -} - -impl InternalTowerHandlerFunc for TFunc -where - TEndpoint: HttpEndpoint, - TFunc: Fn(Arc, Request) -> TFut, - TFut: Future, http::Error>> + Send + 'static, -{ - type Fut = TFut; -} - -/// TODO -#[derive(Debug)] -pub struct TowerEndpoint(Arc, TFunc) -where - TEndpoint: HttpEndpoint, - TFunc: InternalTowerHandlerFunc; - -impl Service for TowerEndpoint -where - TEndpoint: HttpEndpoint, - TFunc: InternalTowerHandlerFunc, -{ - type Response = Response; - type Error = http::Error; - type Future = >::Fut; - - fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) - } - - fn call(&mut self, request: Request) -> Self::Future { - (self.1)(self.0.clone(), request) - } -} - impl Endpoint where TEndpoint: HttpEndpoint, { /// is called to mount the endpoint onto the AWS lambda runtime. - pub fn lambda(mut self) -> TowerEndpoint> { + pub async fn lambda(mut self) -> Result<(), Error> { let (_url, methods) = self.endpoint.register(); // TODO: Handle `_url`?? - TowerEndpoint( - Arc::new(self.endpoint), - is_send(move |endpoint: Arc, request: Request| { - let is_correct_method = methods.as_ref().contains(request.method()); - - is_send(async move { - if !is_correct_method { - return Response::builder() - .status(StatusCode::METHOD_NOT_ALLOWED) - .body("Method Not Allowed".into()); + let endpoint = Arc::new(self.endpoint); + + lambda_http::run(service_fn(move |request: Request| { + let endpoint = endpoint.clone(); + let is_correct_method = methods.as_ref().contains(request.method()); + + async move { + if !is_correct_method { + return Response::builder() + .status(StatusCode::METHOD_NOT_ALLOWED) + .body("Method Not Allowed".to_string().into()); + } + + let (parts, body) = request.into_parts(); + let fut = endpoint.handler(crate::Request( + parts, + match body { + Body::Empty => vec![], + Body::Text(text) => text.into_bytes(), + Body::Binary(binary) => binary, + }, + Server::Lambda, + )); + + match fut.await.into_response() { + Ok(resp) => { + let (parts, body) = resp.into_parts(); + Ok(Response::from_parts(parts, body.into())) } - - let (parts, body) = request.into_parts(); - let fut = endpoint.handler(crate::Request( - parts, - match body { - Body::Empty => vec![], - Body::Text(text) => text.into_bytes(), - Body::Binary(binary) => binary, - }, - Server::Lambda, - )); - - match fut.await.into_response() { - Ok(resp) => { - let (parts, body) = resp.into_parts(); - Ok(Response::from_parts(parts, body.into())) - } - Err(err) => Response::builder() - .status(StatusCode::INTERNAL_SERVER_ERROR) - .header("content-type", "text/html") - .body(err.to_string().into()), - } - }) - }), - ) + Err(err) => Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .header("content-type", "text/html") + .body(Body::Text(err.to_string())), + } + } + })) + .await } } - -// Lambda runtime get's angry. These act as a safety net to prevent breaking the Lambda runtime inside user code. -#[inline] -fn is_send(t: T) -> T { - t -} From 691ce93632b03dce48897f28d4ba5582bd6067ea Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Sat, 1 Apr 2023 19:56:14 +0800 Subject: [PATCH 3/8] upgrade workspace deps --- Cargo.toml | 40 +++++++++---------- examples/cf-workers/Cargo.toml | 4 +- .../netlify/netlify/functions/demo/Cargo.toml | 8 ++-- examples/vercel/Cargo.toml | 4 +- src/ws/tokio_ws.rs | 3 +- 5 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index afc7b12..7130cd4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,36 +46,36 @@ 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.12", optional = true, features = [] } +poem = { version = "1.3.55", optional = true, features = [] } +rocket = { version = "0.5.0-rc.3", optional = true, features = [] } +warp = { version = "0.3.4", optional = true, features = [] } +lambda_http = { version = "0.7.3", optional = true, features = [] } tower = { version = "0.4.13", optional = true, features = [] } -worker = { version = "0.0.12", optional = true, features = [] } +worker = { version = "0.0.15", optional = true, features = [] } tauri = { version = "1.2.4", optional = true, features = ["linux-protocol-headers"] } -vercel_runtime = { version = "0.2.1", optional = true } +vercel_runtime = { version = "0.3.4", optional = true } # Core -cookie = { version = "0.16.1", optional = true, features = ["percent-encode"] } -http = { version = "0.2.8", features = [] } +cookie = { version = "0.17.0", optional = true, features = ["percent-encode"] } +http = { version = "0.2.9", features = [] } form_urlencoded = "1.1.0" -async-tungstenite = { version = "0.19.0", optional = true } +async-tungstenite = { version = "0.20.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" +base64 = { version = "0.21.0", optional = true } +tokio = { version = "1.27.0", features = [], default-features = false, optional = true } +hyper = "0.14.25" # TODO: Remove this if possible or feature gate it. I think Axum needs it. +futures = "0.3.28" +thiserror = "1.0.40" percent-encoding = { version = "2.2.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.27.0", features = ["macros", "rt-multi-thread", "fs"] } +axum = { version = "0.6.12", features = [] } tower = { version = "0.4.13", features = [] } -hyper = { version = "0.14.20", features = [] } -actix-web = "4.2.1" +hyper = { version = "0.14.25", features = [] } +actix-web = "4.3.1" [workspace] members = [ diff --git a/examples/cf-workers/Cargo.toml b/examples/cf-workers/Cargo.toml index 832f579..5a4de18 100644 --- a/examples/cf-workers/Cargo.toml +++ b/examples/cf-workers/Cargo.toml @@ -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.15" +serde_json = "1.0.95" # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires diff --git a/examples/netlify/netlify/functions/demo/Cargo.toml b/examples/netlify/netlify/functions/demo/Cargo.toml index a63fc86..44e0ee6 100644 --- a/examples/netlify/netlify/functions/demo/Cargo.toml +++ b/examples/netlify/netlify/functions/demo/Cargo.toml @@ -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.27.0" +lambda_http = "0.7.3" +tracing-subscriber = "0.3.16" +tracing = "0.1.37" diff --git a/examples/vercel/Cargo.toml b/examples/vercel/Cargo.toml index ceeee56..486dcfb 100644 --- a/examples/vercel/Cargo.toml +++ b/examples/vercel/Cargo.toml @@ -5,9 +5,9 @@ edition = "2021" [dependencies] tokio = { version = "1", features = ["macros"] } -serde_json = { version = "1.0.86", features = ["raw_value"] } +serde_json = { version = "1.0.95", features = ["raw_value"] } httpz = { path = "../..", features = ["vercel"] } -vercel_runtime = { version = "0.2.1" } +vercel_runtime = { version = "0.3.4" } [[bin]] name = "simple" diff --git a/src/ws/tokio_ws.rs b/src/ws/tokio_ws.rs index 10cca8a..9e44222 100644 --- a/src/ws/tokio_ws.rs +++ b/src/ws/tokio_ws.rs @@ -4,6 +4,7 @@ use std::{ }; use async_tungstenite::{self, tokio::TokioAdapter, tungstenite::protocol, WebSocketStream}; +use base64::{engine::general_purpose::STANDARD, Engine}; use futures::{Future, Sink, Stream}; use http::{ header::{self, HeaderName, SET_COOKIE}, @@ -176,7 +177,7 @@ fn sign(key: &[u8]) -> HeaderValue { let mut sha1 = Sha1::default(); sha1.update(key); sha1.update(&b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"[..]); - HeaderValue::from_maybe_shared(base64::encode(sha1.finalize())) + HeaderValue::from_maybe_shared(STANDARD.encode(sha1.finalize())) .expect("base64 is a valid value") } From 2afc85de7c05b5d7d9b74c5439baf5a952162b15 Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Sat, 1 Apr 2023 20:10:52 +0800 Subject: [PATCH 4/8] bruh --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1347cea..7de6329 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,15 +21,16 @@ jobs: - uses: actions/checkout@v3 - name: "[Linux] System dependencies" if: matrix.os == 'ubuntu-latest' - run: sudo apt-get install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev + 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@v3 - name: System dependencies - run: sudo apt-get install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev + 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 From 634e91b09e20201a19b1c2a3eef99875cee23d1b Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Tue, 18 Jul 2023 00:49:54 +0800 Subject: [PATCH 5/8] Upgrade deps --- Cargo.toml | 34 +++++++++---------- examples/cf-workers/Cargo.toml | 4 +-- .../netlify/netlify/functions/demo/Cargo.toml | 6 ++-- examples/tauri/Cargo.toml | 4 +-- examples/vercel/Cargo.toml | 4 +-- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7130cd4..b4d3c01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,34 +47,34 @@ vercel = ["dep:vercel_runtime"] [dependencies] # Webservers actix-web = { version = "4.3.1", optional = true, features = [] } -axum = { version = "0.6.12", optional = true, features = [] } -poem = { version = "1.3.55", 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.4", optional = true, features = [] } -lambda_http = { version = "0.7.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.15", optional = true, features = [] } -tauri = { version = "1.2.4", optional = true, features = ["linux-protocol-headers"] } -vercel_runtime = { version = "0.3.4", optional = true } +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.17.0", optional = true, features = ["percent-encode"] } http = { version = "0.2.9", features = [] } -form_urlencoded = "1.1.0" -async-tungstenite = { version = "0.20.0", optional = true } +form_urlencoded = "1.2.0" +async-tungstenite = { version = "0.22.2", optional = true } sha1 = { version = "0.10.5", optional = true } -base64 = { version = "0.21.0", optional = true } -tokio = { version = "1.27.0", features = [], default-features = false, optional = true } -hyper = "0.14.25" # TODO: Remove this if possible or feature gate it. I think Axum needs it. +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.40" -percent-encoding = { version = "2.2.0", optional = true, features = [] } +thiserror = "1.0.43" +percent-encoding = { version = "2.3.0", optional = true, features = [] } [dev-dependencies] -tokio = { version = "1.27.0", features = ["macros", "rt-multi-thread", "fs"] } -axum = { version = "0.6.12", 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.25", features = [] } +hyper = { version = "0.14.27", features = [] } actix-web = "4.3.1" [workspace] diff --git a/examples/cf-workers/Cargo.toml b/examples/cf-workers/Cargo.toml index 5a4de18..b3595e5 100644 --- a/examples/cf-workers/Cargo.toml +++ b/examples/cf-workers/Cargo.toml @@ -12,8 +12,8 @@ default = ["console_error_panic_hook"] [dependencies] httpz = { path = "../../", features = ["workers"] } cfg-if = "1.0.0" -worker = "0.0.15" -serde_json = "1.0.95" +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 diff --git a/examples/netlify/netlify/functions/demo/Cargo.toml b/examples/netlify/netlify/functions/demo/Cargo.toml index 44e0ee6..93eb816 100644 --- a/examples/netlify/netlify/functions/demo/Cargo.toml +++ b/examples/netlify/netlify/functions/demo/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] httpz = { path = "../../../../../", features = ["lambda"] } -tokio = "1.27.0" -lambda_http = "0.7.3" -tracing-subscriber = "0.3.16" +tokio = "1.29.1" +lambda_http = "0.8.1" +tracing-subscriber = "0.3.17" tracing = "0.1.37" diff --git a/examples/tauri/Cargo.toml b/examples/tauri/Cargo.toml index 25f8133..cca0687 100644 --- a/examples/tauri/Cargo.toml +++ b/examples/tauri/Cargo.toml @@ -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 diff --git a/examples/vercel/Cargo.toml b/examples/vercel/Cargo.toml index 486dcfb..80ee32e 100644 --- a/examples/vercel/Cargo.toml +++ b/examples/vercel/Cargo.toml @@ -5,9 +5,9 @@ edition = "2021" [dependencies] tokio = { version = "1", features = ["macros"] } -serde_json = { version = "1.0.95", features = ["raw_value"] } +serde_json = { version = "1.0.103", features = ["raw_value"] } httpz = { path = "../..", features = ["vercel"] } -vercel_runtime = { version = "0.3.4" } +vercel_runtime = { version = "1.0.2" } [[bin]] name = "simple" From 16da3ed7a11da366e527d3c99cabd7f45d709860 Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Tue, 18 Jul 2023 00:50:04 +0800 Subject: [PATCH 6/8] :tada: Release 0.0.5 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b4d3c01..36aff0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "httpz" -version = "0.0.4" +version = "0.0.5" description = "Code once, support every Rust webserver!" authors = ["Oscar Beaumont "] edition = "2021" From c250433de87ff85c27ccfb721fce6f775ab55c7f Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Sun, 10 Sep 2023 22:16:06 +0800 Subject: [PATCH 7/8] Update Discord link Signed-off-by: Oscar Beaumont --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2cc4643..ca52368 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

httpz

Code once, support every Rust webserver!

- Discord + Discord Crates.io License
From f3050d0a64938f71720b8111fb08be401aa813fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 23:55:54 +0800 Subject: [PATCH 8/8] Bump actions/checkout from 3 to 4 (#35) Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/audit.yml | 2 +- .github/workflows/ci.yml | 4 ++-- .github/workflows/upgrade-dependencies.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 6975cb8..fce87e4 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7de6329..01e296b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - windows-latest runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - 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 @@ -28,7 +28,7 @@ jobs: clippy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - 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 diff --git a/.github/workflows/upgrade-dependencies.yml b/.github/workflows/upgrade-dependencies.yml index 640fcbe..2e34f79 100644 --- a/.github/workflows/upgrade-dependencies.yml +++ b/.github/workflows/upgrade-dependencies.yml @@ -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