-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default headers to request in router
Spin runtimes are expected to add certain headers to each request as can be seen [here](https://github.com/fermyon/spin/blob/efac5cf2249987b80bcb2c11a76564547df72327/crates/trigger-http/src/lib.rs#L498-L534). The most appropriate place for this to happen in `spin-test` is in the router. However, `wasi:http/types/incoming-request` does not allow for modifying the headers as the headers are set to immutable (and any mutating function called on them returns an `wasi:http/types/header-error.immutable`). This is a rather fundamental shortcoming of `wasi:[email protected]` that we won't be able to get around for the foreseeable future. To work around the above, we add an optional `incoming-body` to `fermyon:spin-test/http-helper/new-request` which allows the non-body parts of the request to come from the `outgoing-request` while the body comes from the `incoming-request`. Signed-off-by: Ryan Levick <[email protected]>
- Loading branch information
Showing
9 changed files
with
209 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
// Generated by `wit-bindgen` 0.24.0. DO NOT EDIT! | ||
// Options used: | ||
pub type OutgoingRequest = wasi::http::types::OutgoingRequest; | ||
pub type IncomingRequest = wasi::http::types::IncomingRequest; | ||
pub type IncomingBody = wasi::http::types::IncomingBody; | ||
#[allow(unused_unsafe, clippy::all)] | ||
pub fn get_manifest() -> _rt::String { | ||
unsafe { | ||
|
@@ -47,6 +50,32 @@ pub fn set_component_id(component_id: &str) { | |
wit_import(ptr0.cast_mut(), len0); | ||
} | ||
} | ||
#[allow(unused_unsafe, clippy::all)] | ||
/// See `fermyon:spin-test/http-helper/new-request` for documentation on this function | ||
pub fn new_request( | ||
request: OutgoingRequest, | ||
incoming_body: Option<IncomingBody>, | ||
) -> IncomingRequest { | ||
unsafe { | ||
let (result0_0, result0_1) = match &incoming_body { | ||
Some(e) => (1i32, (e).take_handle() as i32), | ||
None => (0i32, 0i32), | ||
}; | ||
#[cfg(target_arch = "wasm32")] | ||
#[link(wasm_import_module = "$root")] | ||
extern "C" { | ||
#[link_name = "new-request"] | ||
fn wit_import(_: i32, _: i32, _: i32) -> i32; | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
fn wit_import(_: i32, _: i32, _: i32) -> i32 { | ||
unreachable!() | ||
} | ||
let ret = wit_import((&request).take_handle() as i32, result0_0, result0_1); | ||
wasi::http::types::IncomingRequest::from_handle(ret as u32) | ||
} | ||
} | ||
#[allow(dead_code)] | ||
pub mod wasi { | ||
#[allow(dead_code)] | ||
|
@@ -7662,21 +7691,21 @@ pub(crate) use __export_router_impl as export; | |
#[cfg(target_arch = "wasm32")] | ||
#[link_section = "component-type:wit-bindgen:0.24.0:router:encoded world"] | ||
#[doc(hidden)] | ||
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 6523] = *b"\ | ||
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xfe1\x01A\x02\x01A\x19\ | ||
\x01B\x0a\x04\0\x08pollable\x03\x01\x01h\0\x01@\x01\x04self\x01\0\x7f\x04\0\x16[\ | ||
method]pollable.ready\x01\x02\x01@\x01\x04self\x01\x01\0\x04\0\x16[method]pollab\ | ||
le.block\x01\x03\x01p\x01\x01py\x01@\x01\x02in\x04\0\x05\x04\0\x04poll\x01\x06\x03\ | ||
\x01\x12wasi:io/[email protected]\x05\0\x02\x03\0\0\x08pollable\x01B\x0f\x02\x03\x02\x01\ | ||
\x01\x04\0\x08pollable\x03\0\0\x01w\x04\0\x07instant\x03\0\x02\x01w\x04\0\x08dur\ | ||
ation\x03\0\x04\x01@\0\0\x03\x04\0\x03now\x01\x06\x01@\0\0\x05\x04\0\x0aresoluti\ | ||
on\x01\x07\x01i\x01\x01@\x01\x04when\x03\0\x08\x04\0\x11subscribe-instant\x01\x09\ | ||
\x01@\x01\x04when\x05\0\x08\x04\0\x12subscribe-duration\x01\x0a\x03\x01!wasi:clo\ | ||
cks/monotonic[email protected]\x05\x02\x01B\x04\x04\0\x05error\x03\x01\x01h\0\x01@\x01\ | ||
\x04self\x01\0s\x04\0\x1d[method]error.to-debug-string\x01\x02\x03\x01\x13wasi:i\ | ||
o/error@0.2.0\x05\x03\x02\x03\0\x02\x05error\x01B(\x02\x03\x02\x01\x04\x04\0\x05\ | ||
error\x03\0\0\x02\x03\x02\x01\x01\x04\0\x08pollable\x03\0\x02\x01i\x01\x01q\x02\x15\ | ||
last-operation-failed\x01\x04\0\x06closed\0\0\x04\0\x0cstream-error\x03\0\x05\x04\ | ||
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 6682] = *b"\ | ||
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x9d3\x01A\x02\x01A$\x01\ | ||
B\x0a\x04\0\x08pollable\x03\x01\x01h\0\x01@\x01\x04self\x01\0\x7f\x04\0\x16[meth\ | ||
od]pollable.ready\x01\x02\x01@\x01\x04self\x01\x01\0\x04\0\x16[method]pollable.b\ | ||
lock\x01\x03\x01p\x01\x01py\x01@\x01\x02in\x04\0\x05\x04\0\x04poll\x01\x06\x03\x01\ | ||
\x12wasi:io/[email protected]\x05\0\x02\x03\0\0\x08pollable\x01B\x0f\x02\x03\x02\x01\x01\ | ||
\x04\0\x08pollable\x03\0\0\x01w\x04\0\x07instant\x03\0\x02\x01w\x04\0\x08duratio\ | ||
n\x03\0\x04\x01@\0\0\x03\x04\0\x03now\x01\x06\x01@\0\0\x05\x04\0\x0aresolution\x01\ | ||
\x07\x01i\x01\x01@\x01\x04when\x03\0\x08\x04\0\x11subscribe-instant\x01\x09\x01@\ | ||
\x01\x04when\x05\0\x08\x04\0\x12subscribe-duration\x01\x0a\x03\x01!wasi:clocks/m\ | ||
onotonic[email protected]\x05\x02\x01B\x04\x04\0\x05error\x03\x01\x01h\0\x01@\x01\x04\ | ||
self\x01\0s\x04\0\x1d[method]error.to-debug-string\x01\x02\x03\x01\x13wasi:io/er\ | ||
ror@0.2.0\x05\x03\x02\x03\0\x02\x05error\x01B(\x02\x03\x02\x01\x04\x04\0\x05erro\ | ||
r\x03\0\0\x02\x03\x02\x01\x01\x04\0\x08pollable\x03\0\x02\x01i\x01\x01q\x02\x15l\ | ||
ast-operation-failed\x01\x04\0\x06closed\0\0\x04\0\x0cstream-error\x03\0\x05\x04\ | ||
\0\x0cinput-stream\x03\x01\x04\0\x0doutput-stream\x03\x01\x01h\x07\x01p}\x01j\x01\ | ||
\x0a\x01\x06\x01@\x02\x04self\x09\x03lenw\0\x0b\x04\0\x19[method]input-stream.re\ | ||
ad\x01\x0c\x04\0\"[method]input-stream.blocking-read\x01\x0c\x01j\x01w\x01\x06\x01\ | ||
|
@@ -7785,14 +7814,17 @@ e\x01\x8c\x01\x03\x01\x15wasi:http/[email protected]\x05\x09\x02\x03\0\x04\x10incoming | |
-request\x02\x03\0\x04\x11response-outparam\x01B\x08\x02\x03\x02\x01\x0a\x04\0\x10\ | ||
incoming-request\x03\0\0\x02\x03\x02\x01\x0b\x04\0\x11response-outparam\x03\0\x02\ | ||
\x01i\x01\x01i\x03\x01@\x02\x07request\x04\x0cresponse-out\x05\x01\0\x04\0\x06ha\ | ||
ndle\x01\x06\x03\x01\x20wasi:http/[email protected]\x05\x0c\x01@\0\0s\x03\0\ | ||
\x0cget-manifest\x01\x0d\x01@\x01\x0ccomponent-ids\x01\0\x03\0\x10set-component-\ | ||
id\x01\x0e\x01B\x08\x02\x03\x02\x01\x0a\x04\0\x10incoming-request\x03\0\0\x02\x03\ | ||
\x02\x01\x0b\x04\0\x11response-outparam\x03\0\x02\x01i\x01\x01i\x03\x01@\x02\x07\ | ||
request\x04\x0cresponse-out\x05\x01\0\x04\0\x06handle\x01\x06\x04\x01\x20wasi:ht\ | ||
tp/[email protected]\x05\x0f\x04\x01\x15fermyon:router/router\x04\0\x0b\x0c\ | ||
\x01\0\x06router\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-componen\ | ||
t\x070.202.0\x10wit-bindgen-rust\x060.24.0"; | ||
ndle\x01\x06\x03\x01\x20wasi:http/[email protected]\x05\x0c\x02\x03\0\x04\x10\ | ||
outgoing-request\x03\0\x10outgoing-request\x03\0\x0d\x03\0\x10incoming-request\x03\ | ||
\0\x0a\x02\x03\0\x04\x0dincoming-body\x03\0\x0dincoming-body\x03\0\x10\x01@\0\0s\ | ||
\x03\0\x0cget-manifest\x01\x12\x01@\x01\x0ccomponent-ids\x01\0\x03\0\x10set-comp\ | ||
onent-id\x01\x13\x01i\x0e\x01i\x11\x01k\x15\x01i\x0f\x01@\x02\x07request\x14\x0d\ | ||
incoming-body\x16\0\x17\x03\0\x0bnew-request\x01\x18\x01B\x08\x02\x03\x02\x01\x0a\ | ||
\x04\0\x10incoming-request\x03\0\0\x02\x03\x02\x01\x0b\x04\0\x11response-outpara\ | ||
m\x03\0\x02\x01i\x01\x01i\x03\x01@\x02\x07request\x04\x0cresponse-out\x05\x01\0\x04\ | ||
\0\x06handle\x01\x06\x04\x01\x20wasi:http/[email protected]\x05\x19\x04\x01\ | ||
\x15fermyon:router/router\x04\0\x0b\x0c\x01\0\x06router\x03\0\0\0G\x09producers\x01\ | ||
\x0cprocessed-by\x02\x0dwit-component\x070.202.0\x10wit-bindgen-rust\x060.24.0"; | ||
|
||
#[inline(never)] | ||
#[doc(hidden)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.