Skip to content

Commit e5578bb

Browse files
author
zach
authored
refactor(http): avoid copying http response (#11)
1 parent be1e735 commit e5578bb

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

http/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use extism_pdk::*;
22

33
#[plugin_fn]
4-
pub unsafe fn http_get(Json(input): Json<HttpRequest>) -> FnResult<Vec<u8>> {
4+
pub fn http_get(Json(input): Json<HttpRequest>) -> FnResult<Memory> {
55
let res = http::request::<()>(&input, None)?;
6-
let res = res.body();
6+
let res = res.to_memory()?;
77
Ok(res)
88
}
99

@@ -15,8 +15,8 @@ struct HttpRequestWithBody {
1515
}
1616

1717
#[plugin_fn]
18-
pub fn http_post(Json(input): Json<HttpRequestWithBody>) -> FnResult<Vec<u8>> {
18+
pub fn http_post(Json(input): Json<HttpRequestWithBody>) -> FnResult<Memory> {
1919
let res = http::request::<&str>(&input.req, Some(&input.data))?;
20-
let res = res.body();
20+
let res = res.into_memory();
2121
Ok(res)
2222
}

0 commit comments

Comments
 (0)