scotty-web / scotty

Haskell web framework inspired by Ruby's Sinatra, using WAI and Warp (Official Repository)
http://hackage.haskell.org/package/scotty
BSD 3-Clause "New" or "Revised" License
1.71k stars 132 forks source link

Allow customizing status of redirect #401

Open hackeryarn opened 1 month ago

hackeryarn commented 1 month ago

Right now, redirect always issues a 302. This means that the redirect will use the same method. This becomes a problem in a common case of needing to redirect on a DELETE action.

For example, if I have:

  delete "/contacts/:contactId/" $ do
    cid <- S.pathParam "contactId"
    lift $ deleteContact cid
    redirect "/contacts"

it will redirect to DELETE /contacts which is not what I would want. I can easily fix this browser behavior by changing the status to 303, which will cause the next call to be a GET. However, there is no way to to change this status in Scotty.

We could handle this in one of two ways: