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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26bd5103440c1de1bd93ea671635a87e8f25d39fc56fef5025752799e6731edd
4
- data.tar.gz: 92157e6b2962fadcca66aa24b9baf234bf04e093f0c016cd51d8e7542a8da0b1
3
+ metadata.gz: 75adf9317aff9d59ed25ed829aa465be4df1d8fe289c8cc44b5970a7f7cdd990
4
+ data.tar.gz: 114acaec678f72a06e2971520b8118bf33c937875874b290ef053e20a190e8c1
5
5
  SHA512:
6
- metadata.gz: f7f8c267d373d1e0f5ffa730956fc5e2d0bdc43f9143c61e3866596efae583d6e9403c2cf4ead9972af4cd16ee6d6097c5fa01d8974017de6f4a8c571316b7a9
7
- data.tar.gz: 2bebe7b17a804216f59846866d374b4d2b2439ad77aee6ab1e4d51766dbeba6053b896f2906c0feda378d9cbbaa64b695897351113aa3ee3e157cdec20586d4a
6
+ metadata.gz: ff6f8b38c7d515e5d022faeeb9bff7032025996a6aec023b5a21dbb3871cc13924c3555a7d2ae1c060c45817c7f370d310071aed577c1ad6ce2f5df9cf4397f6
7
+ data.tar.gz: 7d572d45508f625c0d48ce6e50049ecca71ba9abe86a130600556c0335974df5502d67848a9935dd6984036ad838f8ba19e89be9f6439cbf2f6435433882317b
data/Cargo.lock CHANGED
@@ -55,7 +55,7 @@ checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
55
55
 
56
56
  [[package]]
57
57
  name = "app_bridge"
58
- version = "4.1.0"
58
+ version = "4.1.1"
59
59
  dependencies = [
60
60
  "base64",
61
61
  "httpmock",
@@ -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.0"
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, Response};
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: resp.status().as_u16(),
326
+ status,
297
327
  headers,
298
- body: resp.text().unwrap_or_default(),
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
  }
@@ -243,6 +243,8 @@ interface http {
243
243
  status: u16,
244
244
  headers: headers,
245
245
  body: string,
246
+ /// Raw response payload for binary responses.
247
+ body-bytes: option<list<u8>>,
246
248
  }
247
249
 
248
250
  record request {
@@ -4,5 +4,5 @@
4
4
  # ext/app_bridge/Cargo.toml file to keep them in sync.
5
5
 
6
6
  module AppBridge
7
- VERSION = "4.1.0"
7
+ VERSION = "4.1.1"
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_bridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Ross