Skip to content

Commit

Permalink
Return WebSocket response headers (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchalmers authored Aug 23, 2024
1 parent d87a555 commit 9287389
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 20 deletions.
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.

2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.15
0.3.16
2 changes: 1 addition & 1 deletion kittycad.rs.patch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"path": "/info/x-rust",
"value": {
"client": "// Authenticate via an API token.\nlet client = kittycad::Client::new(\"$TOKEN\");\n\n// - OR -\n\n// Authenticate with your token and host parsed from the environment variables:\n// `KITTYCAD_API_TOKEN`.\nlet client = kittycad::Client::new_from_env();",
"install": "[dependencies]\nkittycad = \"0.3.15\""
"install": "[dependencies]\nkittycad = \"0.3.16\""
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion kittycad/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "kittycad"
description = "A fully generated & opinionated API client for the KittyCAD API."
version = "0.3.15"
version = "0.3.16"
documentation = "https://docs.rs/kittycad"
readme = "README.md"
repository = "https://github.com/KittyCAD/kittycad.rs/tree/main/kittycad"
Expand Down
2 changes: 1 addition & 1 deletion kittycad/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To install the library, add the following to your `Cargo.toml` file.

```toml
[dependencies]
kittycad = "0.3.15"
kittycad = "0.3.16"
```

## Basic example
Expand Down
5 changes: 3 additions & 2 deletions kittycad/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Executor {
#[cfg(not(target_arch = "wasm32"))]
pub async fn create_term<'a>(
&'a self,
) -> Result<reqwest::Upgraded, crate::types::error::Error> {
) -> Result<(reqwest::Upgraded, http::HeaderMap), crate::types::error::Error> {
let mut req = self.client.client_http1_only.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "ws/executor/term"),
Expand All @@ -93,10 +93,11 @@ impl Executor {
return Err(crate::types::error::Error::UnexpectedResponse(resp));
}

let headers = resp.headers().clone();
let upgraded = resp
.upgrade()
.await
.map_err(crate::types::error::Error::RequestError)?;
Ok(upgraded)
Ok((upgraded, headers))
}
}
2 changes: 1 addition & 1 deletion kittycad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//!
//! ```toml
//! [dependencies]
//! kittycad = "0.3.15"
//! kittycad = "0.3.16"
//! ```
//!
//! ## Basic example
Expand Down
5 changes: 3 additions & 2 deletions kittycad/src/modeling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Modeling {
video_res_height: Option<u32>,
video_res_width: Option<u32>,
webrtc: Option<bool>,
) -> Result<reqwest::Upgraded, crate::types::error::Error> {
) -> Result<(reqwest::Upgraded, http::HeaderMap), crate::types::error::Error> {
let mut req = self.client.client_http1_only.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "ws/modeling/commands"),
Expand Down Expand Up @@ -92,10 +92,11 @@ impl Modeling {
return Err(crate::types::error::Error::UnexpectedResponse(resp));
}

let headers = resp.headers().clone();
let upgraded = resp
.upgrade()
.await
.map_err(crate::types::error::Error::RequestError)?;
Ok(upgraded)
Ok((upgraded, headers))
}
}
2 changes: 1 addition & 1 deletion kittycad/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ async fn test_modeling_websocket() {
.commands_ws(None, None, None, None, None, None, None, None)
.await
{
Ok(ws) => ws,
Ok((ws, _headers)) => ws,
Err(crate::types::error::Error::UnexpectedResponse(resp)) => {
let txt = resp.text().await.unwrap();
panic!("Failed to connect to modeling websocket: {}", txt);
Expand Down
10 changes: 5 additions & 5 deletions kittycad/tests/tabled_one_of.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
+----------------+------------------+----------+------------+-------------+-----------------+-----------+
| FileConversion | FileCenterOfMass | FileMass | FileVolume | FileDensity | FileSurfaceArea | TextToCad |
+----------------+------------------+----------+------------+-------------+-----------------+-----------+
| + | | | | | | |
+----------------+------------------+----------+------------+-------------+-----------------+-----------+
+----------------+------------------+----------+------------+-------------+-----------------+-----------+--------------------+
| FileConversion | FileCenterOfMass | FileMass | FileVolume | FileDensity | FileSurfaceArea | TextToCad | TextToCadIteration |
+----------------+------------------+----------+------------+-------------+-----------------+-----------+--------------------+
| + | | | | | | | |
+----------------+------------------+----------+------------+-------------+-----------------+-----------+--------------------+
6 changes: 4 additions & 2 deletions openapitor/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn generate_websocket_fn(
// Get the function name.
let fn_name = op.get_fn_name()?;
let fn_name_ident = format_ident!("{}", fn_name);
let response_type = quote!(reqwest::Upgraded);
let response_type = quote!((reqwest::Upgraded, http::HeaderMap));
// Get the function args.
let raw_args = get_args(name, method, type_space, op, global_params)?;
// Make sure if we have args, we start with a comma.
Expand Down Expand Up @@ -86,10 +86,12 @@ fn generate_websocket_fn(
if resp.status().is_client_error() || resp.status().is_server_error() {
return Err(crate::types::error::Error::UnexpectedResponse(resp));
}

let headers = resp.headers().clone();
// TODO: This isn't really a request error, but the response was already consumed.
// So we can't use Error::UnexpectedResponse.
let upgraded = resp.upgrade().await.map_err(crate::types::error::Error::RequestError)?;
Ok(upgraded)
Ok((upgraded, headers))
};

let function = quote! {
Expand Down
5 changes: 3 additions & 2 deletions openapitor/tests/types/websocket.rs.gen
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pub async fn example_api_websocket_counter<'a>(
&'a self,
start: Option<u8>,
) -> Result<reqwest::Upgraded, crate::types::error::Error> {
) -> Result<(reqwest::Upgraded, http::HeaderMap), crate::types::error::Error> {
let mut req = self.client.client_http1_only.request(
http::Method::GET,
format!("{}/{}", self.client.base_url, "counter"),
Expand All @@ -30,9 +30,10 @@ pub async fn example_api_websocket_counter<'a>(
if resp.status().is_client_error() || resp.status().is_server_error() {
return Err(crate::types::error::Error::UnexpectedResponse(resp));
}
let headers = resp.headers().clone();
let upgraded = resp
.upgrade()
.await
.map_err(crate::types::error::Error::RequestError)?;
Ok(upgraded)
Ok((upgraded, headers))
}

0 comments on commit 9287389

Please sign in to comment.