tower-web icon indicating copy to clipboard operation
tower-web copied to clipboard

Returning a redirect without content-type causes panic

Open manifest opened this issue 7 years ago • 2 comments

#[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.

manifest avatar Sep 01 '18 11:09 manifest

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())
        }
    }
}

manifest avatar Sep 01 '18 12:09 manifest

I'd keep this open. It can probably be handled betteer.

carllerche avatar Sep 01 '18 17:09 carllerche