scotty icon indicating copy to clipboard operation
scotty copied to clipboard

Allow customizing status of redirect

Open hackeryarn opened this issue 8 months ago • 0 comments

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:

  • Have redirect respect the the status set by a previous status call.
  • Create a redirectStatus that also takes a status and URL parameter.

hackeryarn avatar Jun 09 '24 20:06 hackeryarn