Closed benwis closed 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.
Oh ResponseOptions
is an Arc<RwLock<...>>
internally so it doesn't matter if the contents are Clone.
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.
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