tower-web
tower-web copied to clipboard
Returning a redirect without content-type causes panic
#[derive(Response)]
#[web(status = "303")]
struct RedirectResponse {
#[web(header)]
location: String
}
impl_web! {
impl Object {
#[get("/")]
fn read(&self) -> Result<RedirectResponse, ()> {
Ok(RedirectResponse {
location: "https://example.org".to_owned(),
})
}
}
}
thread 'tokio-runtime-worker-0' panicked at 'no default content type associated with action', libcore/option.rs:960:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
Perhaps for this case using http::Response would be more convenient.
impl_web! {
impl Object {
#[get("/")]
fn read(&self) -> Result<http::Response<&'static str>, ()> {
Ok(Response::builder()
.header("location", uri)
.status(StatusCode::SEE_OTHER)
.body("")
.unwrap())
}
}
}
I'd keep this open. It can probably be handled betteer.