fermyon / leptos-spin

Integration library for running server-side Leptos apps on Spin
27 stars 6 forks source link

Add header modification for route handlers #17

Closed benwis closed 5 months ago

benwis commented 5 months ago

We'll need to add headers to ResponseOptions, and the spin_sdk Headers type doesn't implement Clone, which'll make this harder. I suppose I can either write my own type for headers that converts into Vec<(String, Vec<u8>)> or try to get that change merged in. Fields implements Clone, but I don't think there's a From impl between Fields and Headers, so that's another path

itowlson commented 5 months ago

Headers is just a type alias for Fields: https://docs.rs/spin-sdk/latest/spin_sdk/http/type.Headers.html

Also, note that (you're going to love this) although Fields has a clone() method, it does not implement Clone. (https://docs.rs/spin-sdk/latest/spin_sdk/http/struct.Fields.html#method.clone) I expect this is because Fields is defined in WIT and wit-bindgen doesn't generate the Clone trait despite the existence of the method. I don't know if this matters - presumably we can still manually implement Clone on ResponseOptions even if we can't derive it.

itowlson commented 5 months ago

Oh ResponseOptions is an Arc<RwLock<...>> internally so it doesn't matter if the contents are Clone.

benwis commented 5 months ago

Technically I suppose it doesn't, it's Arc<RwLock<>> so that we can pass it in on initial routing and have something the user can mutate that we can reference later to construct the Response. Also useful for the Axum integration where we have a bunch of move closures.