Skip to content

Commit

Permalink
Update tauri, axum and http crates
Browse files Browse the repository at this point in the history
 - Adjust httpz code to match new axum API
  • Loading branch information
HeavenVolkoff committed Oct 8, 2024
1 parent 8234227 commit 94c6de1
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ specta = { version = "=2.0.0-rc.20", features = ["derive", "serde"
specta-datatype-from = { git = "https://github.com/specta-rs/specta", rev = "8509af0162" }
specta-serde = { version = "=0.0.7" }
specta-typescript = { version = "=0.0.7", features = ["function"] }
tauri = { version = "2.0.1", optional = true }
tauri = { version = "2.0.2", optional = true }
thiserror = "1.0"
tokio = { version = "1.40", features = ["macros", "rt", "sync"] }
tracing = { version = "0.1.37" }
Expand Down
6 changes: 3 additions & 3 deletions httpz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ keywords = ["async", "http", "httpz", "web", "websockets"]

[dependencies]
async-tungstenite = { version = "0.28.0", features = ["tokio-runtime"] }
axum = { version = "0.6.20", features = [] }
axum = { version = "0.7.7", features = ["macros"] }
base64 = { version = "0.22.1" }
form_urlencoded = "1.2.0"
futures = "0.3.28"
http = { version = "0.2.12", features = [] }
http = { version = "1.1.0", features = [] }
hyper = "0.14.27" # TODO: Remove this if possible or feature gate it. I think Axum needs it.
percent-encoding = { version = "2.3.0", features = [] }
sha1 = { version = "0.10.5" }
Expand All @@ -34,5 +34,5 @@ tokio = { version = "1.29.1", features = [], default-features = fals
tracing = { version = "0.1.37" }

[dev-dependencies]
axum = { version = "0.6.20", features = [] }
axum = { version = "0.7.7", features = [] }
tokio = { version = "1.29.1", features = ["fs", "macros", "rt-multi-thread"] }
32 changes: 21 additions & 11 deletions httpz/src/servers/axum.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::sync::Arc;

use axum::{
extract::State,
body::to_bytes,
extract::{Request, State},
routing::{on, MethodFilter},
Router,
};
use http::{HeaderMap, Request, StatusCode};
use hyper::{body::to_bytes, Body};
use http::{header::CONTENT_LENGTH, HeaderMap, StatusCode};

use crate::{Endpoint, HttpEndpoint, HttpResponse, Server};

Expand All @@ -24,23 +24,33 @@ where
let (url, methods) = self.endpoint.register();
let endpoint = Arc::new(self.endpoint);

let mut method_filter = MethodFilter::empty();
let mut method_filter: Option<MethodFilter> = None;
for method in methods.as_ref().iter() {
method_filter.insert(
MethodFilter::try_from(method.clone())
.expect("Error converting method to MethodFilter"),
);
let method = MethodFilter::try_from(method.clone())
.expect("Error converting method to MethodFilter");
if let Some(ref mut filter) = method_filter {
*filter = filter.or(method);
} else {
method_filter = Some(method);
}
}

Router::<S>::new().route(
url.as_ref(),
on(
method_filter,
|state: State<S>, request: Request<Body>| async move {
method_filter.expect("No methods found"),
|State(state): State<S>, request: Request| async move {
let (mut parts, body) = request.into_parts();
parts.extensions.insert(state);

let body = match to_bytes(body).await {
let content_length = parts
.headers
.get(CONTENT_LENGTH)
.and_then(|value| value.to_str().ok())
.and_then(|value| value.parse::<usize>().ok())
.unwrap_or(10 * 1024 * 1024); // Default to 10MB if not present

let body = match to_bytes(body, content_length).await {
Ok(body) => body.to_vec(),
Err(err) => {
return (
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"tauri": "pnpm --filter @spacedrive/rspc-tauri -- "
},
"devDependencies": {
"typescript": "^5.6.2",
"typescript": "^5.6.3",
"@ianvs/prettier-plugin-sort-imports": "^4.3.1"
},
"packageManager": "[email protected].0"
"packageManager": "[email protected].1"
}
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
},
"peerDependencies": {
"react": "^18.3.1",
"@spacedrive/rspc-client": "^1.0"
"@spacedrive/rspc-client": "^0.2.0"
}
}
4 changes: 2 additions & 2 deletions packages/tauri/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"license": "MIT",
"main": "src/v2.ts",
"dependencies": {
"@tauri-apps/api": "^2.0.1"
"@tauri-apps/api": "^2.0.2"
},
"devDependencies": {
"@spacedrive/rspc-client": "workspace:*"
},
"peerDependencies": {
"@spacedrive/rspc-client": "^1.0"
"@spacedrive/rspc-client": "^0.2.0"
}
}
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

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

0 comments on commit 94c6de1

Please sign in to comment.