app_bridge 4.1.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Cargo.lock +1 -1
- data/ext/app_bridge/Cargo.toml +1 -1
- data/ext/app_bridge/src/request_builder.rs +72 -14
- data/ext/app_bridge/wit/v4_1/world.wit +2 -0
- data/lib/app_bridge/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 75adf9317aff9d59ed25ed829aa465be4df1d8fe289c8cc44b5970a7f7cdd990
|
|
4
|
+
data.tar.gz: 114acaec678f72a06e2971520b8118bf33c937875874b290ef053e20a190e8c1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff6f8b38c7d515e5d022faeeb9bff7032025996a6aec023b5a21dbb3871cc13924c3555a7d2ae1c060c45817c7f370d310071aed577c1ad6ce2f5df9cf4397f6
|
|
7
|
+
data.tar.gz: 7d572d45508f625c0d48ce6e50049ecca71ba9abe86a130600556c0335974df5502d67848a9935dd6984036ad838f8ba19e89be9f6439cbf2f6435433882317b
|
data/Cargo.lock
CHANGED
data/ext/app_bridge/Cargo.toml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name = "app_bridge"
|
|
3
3
|
# When updating the version, please also update the version in the
|
|
4
4
|
# lib/app_bridge/version.rb file to keep them in sync.
|
|
5
|
-
version = "4.1.
|
|
5
|
+
version = "4.1.1"
|
|
6
6
|
edition = "2021"
|
|
7
7
|
authors = ["Alexander Ross <ross@standout.se>"]
|
|
8
8
|
publish = false
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
use crate::app_state::AppState;
|
|
2
2
|
use crate::component::{v3, v4, v4_1};
|
|
3
|
-
use crate::component::v4::standout::app::http::{Method, Request, RequestError
|
|
3
|
+
use crate::component::v4::standout::app::http::{Method, Request, RequestError};
|
|
4
4
|
use reqwest::Method as ReqwestMethod;
|
|
5
5
|
use std::result::Result::Ok;
|
|
6
6
|
use wasmtime::component::Resource;
|
|
@@ -212,16 +212,6 @@ macro_rules! impl_http_type_conversions {
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
impl From<Response> for $v::standout::app::http::Response {
|
|
216
|
-
fn from(r: Response) -> Self {
|
|
217
|
-
Self {
|
|
218
|
-
status: r.status,
|
|
219
|
-
headers: r.headers,
|
|
220
|
-
body: r.body,
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
215
|
impl From<Request> for $v::standout::app::http::Request {
|
|
226
216
|
fn from(r: Request) -> Self {
|
|
227
217
|
Self {
|
|
@@ -243,6 +233,32 @@ macro_rules! impl_http_type_conversions {
|
|
|
243
233
|
};
|
|
244
234
|
}
|
|
245
235
|
|
|
236
|
+
macro_rules! impl_http_response_conversion {
|
|
237
|
+
($v:ident, with_bytes) => {
|
|
238
|
+
impl From<Response> for $v::standout::app::http::Response {
|
|
239
|
+
fn from(r: Response) -> Self {
|
|
240
|
+
Self {
|
|
241
|
+
status: r.status,
|
|
242
|
+
headers: r.headers,
|
|
243
|
+
body: r.body,
|
|
244
|
+
body_bytes: r.body_bytes,
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
($v:ident, no_bytes) => {
|
|
250
|
+
impl From<Response> for $v::standout::app::http::Response {
|
|
251
|
+
fn from(r: Response) -> Self {
|
|
252
|
+
Self {
|
|
253
|
+
status: r.status,
|
|
254
|
+
headers: r.headers,
|
|
255
|
+
body: r.body,
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
246
262
|
// ============================================================================
|
|
247
263
|
// Generate implementations for all supported versions
|
|
248
264
|
// When adding v5, just add:
|
|
@@ -255,13 +271,23 @@ impl_host_request_builder!(v4, no);
|
|
|
255
271
|
impl_host_request_builder!(v4_1, yes);
|
|
256
272
|
|
|
257
273
|
impl_http_type_conversions!(v3);
|
|
258
|
-
// Note: v4 doesn't need conversions since we use v4 types as the canonical internal types
|
|
259
274
|
impl_http_type_conversions!(v4_1);
|
|
275
|
+
impl_http_response_conversion!(v3, no_bytes);
|
|
276
|
+
impl_http_response_conversion!(v4, no_bytes);
|
|
277
|
+
impl_http_response_conversion!(v4_1, with_bytes);
|
|
260
278
|
|
|
261
279
|
// ============================================================================
|
|
262
280
|
// Shared request sending logic
|
|
263
281
|
// ============================================================================
|
|
264
282
|
|
|
283
|
+
#[derive(Debug, Clone)]
|
|
284
|
+
struct Response {
|
|
285
|
+
status: u16,
|
|
286
|
+
headers: Vec<(String, String)>,
|
|
287
|
+
body: String,
|
|
288
|
+
body_bytes: Option<Vec<u8>>,
|
|
289
|
+
}
|
|
290
|
+
|
|
265
291
|
fn send_request(
|
|
266
292
|
client: &std::sync::Arc<std::sync::Mutex<reqwest::blocking::Client>>,
|
|
267
293
|
request: &Request,
|
|
@@ -281,6 +307,7 @@ fn send_request(
|
|
|
281
307
|
|
|
282
308
|
match builder.send() {
|
|
283
309
|
Ok(resp) => {
|
|
310
|
+
let status = resp.status().as_u16();
|
|
284
311
|
let headers = resp
|
|
285
312
|
.headers()
|
|
286
313
|
.iter()
|
|
@@ -292,10 +319,14 @@ fn send_request(
|
|
|
292
319
|
})
|
|
293
320
|
.collect();
|
|
294
321
|
|
|
322
|
+
let bytes = resp.bytes().unwrap_or_default().to_vec();
|
|
323
|
+
let body = String::from_utf8(bytes.clone()).unwrap_or_default();
|
|
324
|
+
|
|
295
325
|
Ok(Response {
|
|
296
|
-
status
|
|
326
|
+
status,
|
|
297
327
|
headers,
|
|
298
|
-
body
|
|
328
|
+
body,
|
|
329
|
+
body_bytes: Some(bytes),
|
|
299
330
|
})
|
|
300
331
|
}
|
|
301
332
|
Err(error) => Err(RequestError::Other(format!(
|
|
@@ -343,6 +374,7 @@ impl Default for Response {
|
|
|
343
374
|
status: 0,
|
|
344
375
|
headers: Vec::new(),
|
|
345
376
|
body: String::new(),
|
|
377
|
+
body_bytes: None,
|
|
346
378
|
}
|
|
347
379
|
}
|
|
348
380
|
}
|
|
@@ -422,4 +454,30 @@ mod tests {
|
|
|
422
454
|
assert_eq!(response.status, 200);
|
|
423
455
|
mock.assert();
|
|
424
456
|
}
|
|
457
|
+
|
|
458
|
+
#[test]
|
|
459
|
+
fn returns_binary_response_body_bytes() {
|
|
460
|
+
use v4_1::standout::app::http::HostRequestBuilder;
|
|
461
|
+
|
|
462
|
+
let server = MockServer::start();
|
|
463
|
+
let body = b"%PDF-1.3".to_vec();
|
|
464
|
+
let mock = server.mock(|when, then| {
|
|
465
|
+
when.method(POST).path("/download");
|
|
466
|
+
then.status(200)
|
|
467
|
+
.header("Content-Type", "application/pdf")
|
|
468
|
+
.body(body.clone());
|
|
469
|
+
});
|
|
470
|
+
let url = format!("{}/download", server.base_url());
|
|
471
|
+
|
|
472
|
+
let mut app_state = AppState::default();
|
|
473
|
+
let builder = app_state.new();
|
|
474
|
+
let builder = app_state.method(builder, v4_1::standout::app::http::Method::Post);
|
|
475
|
+
let builder = app_state.url(builder, url);
|
|
476
|
+
|
|
477
|
+
let response = app_state.send(builder).expect("Request failed");
|
|
478
|
+
|
|
479
|
+
assert_eq!(response.status, 200);
|
|
480
|
+
assert_eq!(response.body_bytes, Some(body));
|
|
481
|
+
mock.assert();
|
|
482
|
+
}
|
|
425
483
|
}
|
data/lib/app_bridge/version.rb
CHANGED