#Clean query params on HttpResponse

1 messages · Page 1 of 1 (latest)

storm lynx
hardy solstice
storm lynx
#

I say 3rd party lightly.. just trying to understand actix-web is out of scope for facilitating redirects?

hardy solstice
#

this particular feature will be in the next version of actix web

#

though redirects are just 307 responses with a Location header

storm lynx
#

I see, where you announced this crate about a year ago

#

Thank you for this

hardy solstice
storm lynx
#

I'm using the dependency.. Tested it and it works.. I guess my question.. what other cool little magic utilities would make it where I would want to use this crate besides this redirect? Any other cool tidbits that are low hanging fruit?

#

i know this is an unrelated help question.. but let's say i have 2 arms of code within a service .. like

  match queryparam {
    None => Ok(HttpResponse::Ok().body(body))
    Some(queryparam) => Ok(Redirect::to("/"))
}

how would I avoid mismatched types?

mismatched types
expected struct `HttpResponse`
   found struct `Redirect`
hardy solstice
hardy solstice
# storm lynx i know this is an unrelated help question.. but let's say i have 2 arms of code ...

yep, fair, two options:

  1. https://docs.rs/actix-web/latest/actix_web/web/enum.Either.html
match queryparam {
    None => Ok(Either::Left(HttpResponse::Ok().body(body)))
    Some(queryparam) => Ok(Either::Right(Redirect::to("/")))
}

2. https://docs.rs/actix-web/latest/actix_web/trait.Responder.html#tymethod.respond_to

match queryparam {
    None => Ok(HttpResponse::Ok().body(body))
    Some(queryparam) => Ok(Redirect::to("/").respond_to(&req))
}

actually 2 wont work very well for you, stick to 1.

storm lynx
#

option 1, is pretty much only binary left/right ? if for some reason i needed a third option would i need to do something else?

#

or would i have nested left/right's?

hardy solstice
#

nested eithers yea, but okay lets give a better answer for >2 variants

#
match option {
    One => Ok(HttpResponse::Ok().body(body).map_into_boxed_body())
    Two => Ok(Redirect::to("/").respond_to(&req).map_into_boxed_body())
    Three => Ok(Json(foo).respond_to(&req).map_into_boxed_body())
}
#

it starts getting a bit wordy, but it's a language limitation

storm lynx
#

ahh .map_into_boxed_body() the secret equalizer i didn't know about

storm lynx
hardy solstice
#

yep